函数原型: ShowMessage(HWND hwnd,uint msg,int wp,int lp)
COM导入进C#: ShowMessage(_RemotableHandle hwnd,uint msg,int wp,int lp)
导入COM之后 在C++中调用直接用HWND句柄类型,而在C#中,类型为_RemotableHandle,此为一个结构:
public struct _RemotableHandle
{
public int fContext;
public __MIDL_IWinTypes_0009 u;
}
public struct __MIDL_IWinTypes_0009
{
public int hInproc;
public int hRemote;
}
那么C#中的窗口句柄IntPtr是不能as到_RemotableHandle结构,也不能强制类型转换. 尝试Marshal.PtrToStructure 仍然失败.最后采用以下方法成功:
unsafe
{
RemotableHandle* rh = (_RemotableHandle*)this.Handle.ToPointer();
ShowMessage(ref *rh, 0x1000, 0, 0);
}