您的位置:首页 > 编程语言 > C#

COM导入到C#开发 HWND句柄类型 对应于C#的 _RemotableHandle结构处理

2009-11-26 01:19 417 查看
函数原型:            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); 

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# struct c
相关文章推荐