我需要从 C# 应用程序调用 VC++ dll 中的回调函数。下面是VC++中的回调函数。
INT_PTR CALLBACK My_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
. . . . .
}
我已经导入了 dll,但我不知道如何从 C# 调用该函数。有什么想法吗?
public class testClass
{
internal static class UnsafeNativeMethods
{
const string _dllLocation = "test.dll";
[DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)]
public static extern int My_Proc(int value1, int value2, Int64 value3, int value4);// am getting stuck here
}
}
最佳答案
正确的声明是:
[DllImport("test.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr My_Proc(IntPtr hDlg, int message, IntPtr wparam, IntPtr lparam);
这是 native 对话的对话过程的声明。 Windows 应该调用它,而不是你。当新的 Windows 消息可用于对话框时,它会这样做。它很少从 DLL 导出,这也可以解释有问题。获得正确的窗口句柄 (hDlg) 也不容易。但是您没有很好地记录您的问题,所以我只能猜测。
关于c# - 从 C# 调用 VC++ dll 中的回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9189878/