DLLImport PInvokeStackImbalance

时间:2015-03-24 03:22:30

标签: c# .net pinvoke dllimport

我正在尝试包装bass.dll。简单的功能不太高级。不想深入了解。但是我遇到了问题。 这是我导入函数的方式:

        [DllImport("bass.dll")]
        public static extern long BASS_Start();
        [DllImport("bass.dll")]
        public static extern bool BASS_Init(int device, uint freq, uint flag, IntPtr hParent, uint GUID);
        [DllImport("bass.dll")]
        public static extern long BASS_StreamCreateFile(bool mem, string file, uint offset, uint length, uint flags);
        [DllImport("bass.dll")]
        public static extern long BASS_ChannelPlay(long handle, long restart);
        [DllImport("user32.dll")]

但是当我打电话给他们时,它不起作用。我得到PInvokeStackImbalance错误。

Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Users\test\Desktop\testv.1.0.0\update\updated\test\test\bin\Release\test.exe'.

Additional information: A call to PInvoke function 'test!test.Main::BASS_StreamCreateFile' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

这就是我打电话给他们的方式。

        BASS_Start();
        BASS_Init(-1, 44100, 0, IntPtr.Zero, 0);
        long handle = BASS_StreamCreateFile(false, @"C:\Users\test\Desktop\James Morrison.mp3", 0, 0, 0);
        //MessageBox.Show("Playing: " + handle.ToString());
        BASS_ChannelPlay(handle, 1);
        Thread.Sleep(10000);

我试过去激活PInvokeStackImbalance但它没有改变任何东西。刚刚停止发生PInvokeStackImbalance。因此它不起作用。

有什么想法吗?

提前谢谢。

P.S。请不要给我建议使用Bass.Net。

1 个答案:

答案 0 :(得分:1)

你的翻译非常错误。我不敢说每一个都有错误。

他们应该是:

[DllImport("bass.dll")]
public static extern bool BASS_Start();

[DllImport("bass.dll")]
public static extern bool BASS_Init(int device, uint freq, uint flag, 
     IntPtr hParent, ref GUID guid);

[DllImport("bass.dll")]
public static extern uint BASS_StreamCreateFile(bool mem, string file, ulong offset, 
    ulong length, uint flags);

[DllImport("bass.dll")]
public static extern bool BASS_ChannelPlay(uint handle, bool restart);

我建议你确保手边有BASS C ++头文件,并且你修改了你对C ++和C#基本类型的了解。