Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using lame_enc.dll in .NET - Signature mismatch

Using lame_enc.dll in .NET - Signature mismatch

Scheduled Pinned Locked Moved C#
helpcsharpcomregextutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChrisHinde
    wrote on last edited by
    #1

    I'm working on a program that will convert a wav-file to mp3, tag it and then upload it via FTP. I'm done with the FTP-part and am now working on the converting to MP3 part (the only thing left). The plan is to use LAME (lame_enc.dll) to do the encoding/converting (unless you have any other suggestion). But I've hit a snag. I couldn't find any good examples for Lame & .NET. I found this here on TCP: C# MP3 Compressor[^] It wouldn't compile due to missing form components, but I copied the the classes that's relevant. The project compiles but I get an exception on the call to beInitStream (in the constructor of Mp3Writer). The error states:

    PInvokeStackImbalance was detected

    and that "the managed PInvoke signature didn't match the unmanaged target signature" (translated from Swedish). Is there anyone that has an idea what's wrong?! Is this code written for an older version of lame_enc.dll (I've looked at the documentation, but can't see the problem)? I also tried to use IntPtr etc (found in another example for another DLL), but same result:

    Marshal.StructureToPtr(Marshal.SizeOf(m_Mp3Config), Marshal.AllocHGlobal(pConfig), false);

    uint LameResult = Lame_encDll.beInitStream(ref pConfig, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream);

    Code for DLL import:

    [DllImport("Lame_enc.dll")]
    public static extern uint beInitStream(ref BE_CONFIG pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

    or

    [DllImport("Lame_enc.dll")]
    public static extern uint beInitStream(ref IntPtr pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

    I could just call lame.exe, but I don't want to do it, mainly because I want to report the progress. Glad for any help/ideas!

    L B D 3 Replies Last reply
    0
    • C ChrisHinde

      I'm working on a program that will convert a wav-file to mp3, tag it and then upload it via FTP. I'm done with the FTP-part and am now working on the converting to MP3 part (the only thing left). The plan is to use LAME (lame_enc.dll) to do the encoding/converting (unless you have any other suggestion). But I've hit a snag. I couldn't find any good examples for Lame & .NET. I found this here on TCP: C# MP3 Compressor[^] It wouldn't compile due to missing form components, but I copied the the classes that's relevant. The project compiles but I get an exception on the call to beInitStream (in the constructor of Mp3Writer). The error states:

      PInvokeStackImbalance was detected

      and that "the managed PInvoke signature didn't match the unmanaged target signature" (translated from Swedish). Is there anyone that has an idea what's wrong?! Is this code written for an older version of lame_enc.dll (I've looked at the documentation, but can't see the problem)? I also tried to use IntPtr etc (found in another example for another DLL), but same result:

      Marshal.StructureToPtr(Marshal.SizeOf(m_Mp3Config), Marshal.AllocHGlobal(pConfig), false);

      uint LameResult = Lame_encDll.beInitStream(ref pConfig, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream);

      Code for DLL import:

      [DllImport("Lame_enc.dll")]
      public static extern uint beInitStream(ref BE_CONFIG pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

      or

      [DllImport("Lame_enc.dll")]
      public static extern uint beInitStream(ref IntPtr pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

      I could just call lame.exe, but I don't want to do it, mainly because I want to report the progress. Glad for any help/ideas!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, P/Invoke stack problems are caused by a calling convention mismatch. This[^] may help you. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      1 Reply Last reply
      0
      • C ChrisHinde

        I'm working on a program that will convert a wav-file to mp3, tag it and then upload it via FTP. I'm done with the FTP-part and am now working on the converting to MP3 part (the only thing left). The plan is to use LAME (lame_enc.dll) to do the encoding/converting (unless you have any other suggestion). But I've hit a snag. I couldn't find any good examples for Lame & .NET. I found this here on TCP: C# MP3 Compressor[^] It wouldn't compile due to missing form components, but I copied the the classes that's relevant. The project compiles but I get an exception on the call to beInitStream (in the constructor of Mp3Writer). The error states:

        PInvokeStackImbalance was detected

        and that "the managed PInvoke signature didn't match the unmanaged target signature" (translated from Swedish). Is there anyone that has an idea what's wrong?! Is this code written for an older version of lame_enc.dll (I've looked at the documentation, but can't see the problem)? I also tried to use IntPtr etc (found in another example for another DLL), but same result:

        Marshal.StructureToPtr(Marshal.SizeOf(m_Mp3Config), Marshal.AllocHGlobal(pConfig), false);

        uint LameResult = Lame_encDll.beInitStream(ref pConfig, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream);

        Code for DLL import:

        [DllImport("Lame_enc.dll")]
        public static extern uint beInitStream(ref BE_CONFIG pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

        or

        [DllImport("Lame_enc.dll")]
        public static extern uint beInitStream(ref IntPtr pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

        I could just call lame.exe, but I don't want to do it, mainly because I want to report the progress. Glad for any help/ideas!

        B Offline
        B Offline
        BobJanova
        wrote on last edited by
        #3

        A stack imbalance means either you passed the wrong number of parameters, or you used the wrong calling convention (which essentially amounts to the same thing underneath).

        1 Reply Last reply
        0
        • C ChrisHinde

          I'm working on a program that will convert a wav-file to mp3, tag it and then upload it via FTP. I'm done with the FTP-part and am now working on the converting to MP3 part (the only thing left). The plan is to use LAME (lame_enc.dll) to do the encoding/converting (unless you have any other suggestion). But I've hit a snag. I couldn't find any good examples for Lame & .NET. I found this here on TCP: C# MP3 Compressor[^] It wouldn't compile due to missing form components, but I copied the the classes that's relevant. The project compiles but I get an exception on the call to beInitStream (in the constructor of Mp3Writer). The error states:

          PInvokeStackImbalance was detected

          and that "the managed PInvoke signature didn't match the unmanaged target signature" (translated from Swedish). Is there anyone that has an idea what's wrong?! Is this code written for an older version of lame_enc.dll (I've looked at the documentation, but can't see the problem)? I also tried to use IntPtr etc (found in another example for another DLL), but same result:

          Marshal.StructureToPtr(Marshal.SizeOf(m_Mp3Config), Marshal.AllocHGlobal(pConfig), false);

          uint LameResult = Lame_encDll.beInitStream(ref pConfig, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream);

          Code for DLL import:

          [DllImport("Lame_enc.dll")]
          public static extern uint beInitStream(ref BE_CONFIG pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

          or

          [DllImport("Lame_enc.dll")]
          public static extern uint beInitStream(ref IntPtr pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);

          I could just call lame.exe, but I don't want to do it, mainly because I want to report the progress. Glad for any help/ideas!

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          I can't see anything obviously wrong from what you've posted. I've had a quick look online at the C definition for the function and I would declare it like:

          [DllImport("Lame_enc.dll")]
          public static extern int beInitStream(ref BE_CONFIG config, out int samples, out int bufferSize, out IntPtr streamHandle);

          I've used out rather than ref for the last 3 parameters as this[^] suggests that these values are returned by the function so no need to pass a reference in. Edit: Be sure to check the return value from the function. It will be one of these constants:

          public const int BE_ERR_SUCCESSFUL = 0x00000000;
          public const int BE_ERR_INVALID_FORMAT = 0x00000001;
          public const int BE_ERR_INVALID_FORMAT_PARAMETERS = 0x00000002;
          public const int BE_ERR_NO_MORE_HANDLES = 0x00000003;
          public const int BE_ERR_INVALID_HANDLE = 0x00000004;
          public const int BE_ERR_BUFFER_TOO_SMALL = 0x00000005;

          Dave
          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups