DLL导入PInvokeStackImbalance

DLLImport PInvokeStackImbalance

我正在尝试包装 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.

你的翻译错得很厉害。每一个都有错误,我不敢说。

它们应该是:

[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# 的基本类型的了解。