.net中调用com的具体操作(总结)
获得某个com实例的接口地址(知道此实例的具体接口)
IntPtr ppv = Marshal.GetComInterfaceForObject( this.m_view, typeof(HelperItems.IShellView) );
获得某个com实例的接口地址(不知道此实例的具体接口)
IntPtr iunkMe = Marshal.GetIUnknownForObject(this);
通过riid,获得具体的接口地址
Marshal.QueryInterface( iunkMe, ref riid, out ppv );
从某个com实例的接口地址获得这个实例
HelperItems.ICommDlgBrowser cdlg = (HelperItems.ICommDlgBrowser) Marshal.GetObjectForIUnknown( Marshal.GetComInterfaceForObject(this.m_view.m_shell, typeof(HelperItems.ICommDlgBrowser)) );
注意 获取对象的某种接口指针 可以在marshal.queryinterface和mashal.getcominterfaceforobject中间选择
此方法成功 ppv = Marshal.GetComInterfaceForObject(dropHandle, typeof(IDropTarget));
此方法没有成功 Marshal.QueryInterface(iunkDropHandle, ref guidIDropTarget, out ppv)
将传入的结构指针所指结构拷贝到管理代码中来
Dim videoHeader As VIDEOHDR = New VIDEOHDR
videoHeader = CType(GetStructure(lpVHdr, videoHeader), VIDEOHDR) ' lpVHdr是传入的结构指针
Public Shared Function GetStructure(ByVal ptr As IntPtr, ByVal struc As ValueType) As Object
Return Marshal.PtrToStructure(ptr, struc.GetType())
End Function
posted on 2004-11-17 16:22 philip_xu 阅读(1758) 评论(1) 编辑 收藏 举报