最近因需要,用C++写了个钩子的DLL,一切工作测试通过后,放到C#里使用P/Invoke调用,发现部分乱码,最后反复测试,才发现一个问题,原来SetWindowsHookEx这个函数,也是分A版和W版,最后换了就正常了,附上对比。。
乱码
[DllImport("user32.dll", SetLastError = true]
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);
正常
[DllImport("user32.dll", SetLastError = true,CharSet = CharSet.Unicode)]
public static extern IntPtr SetWindowsHookExW(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);
标签:IntPtr,C#,DllImport,C++,DLL,乱码
From: https://www.cnblogs.com/push-lou/p/18334672