c# - 从 C# 调用 VC++ dll 中的回调函数

标签 c# callback

我需要从 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/

相关文章:

javascript - for循环,回调,超时一起,超时似乎不起作用

python - Twisted:延迟重复触发?

c# - 拦截 HTTP 请求

c# - 如何防止 ASP.net core 中的默认 url 解码

c# - 未找到monogame内容加载文件异常

c# - 将 asp.net MVC 从 5.0.0-beta2 更新到 5.0.0-rc1

javascript - 在回调中访问对象变量

C# Graphics.DrawString RectangleF 自动高度 : How to find that height?

ios - 我将如何围绕 XML 请求创建回调?

jquery回调