4
我試圖執行此功能:如何獲取指向接口的指針?
public static int QueryInterface(
IntPtr pUnk,
ref Guid iid,
out IntPtr ppv
)
其中
pUnk
Type: System.IntPtr
The interface to be queried.
基本上,Marshal.QueryInterface從COM對象請求指向指定接口。我想查詢一些接口(全部來自IPersist),那麼我該如何去獲取這些接口的引用指針呢?
注意:IPersistStorage就是其中之一。
編輯(這工作):
// Use the CLSID to instantiate the COM object using interop.
Type type = Type.GetTypeFromCLSID(myGuid);
Object comObj = Activator.CreateInstance(type);
// Return a pointer to the objects IUnknown interface.
IntPtr pIUnk = Marshal.GetIUnknownForObject(comObj);
IntPtr pInterface;
Int32 result = Marshal.QueryInterface(pIUnk, ref myGuid, out pInterface);
謝謝。我會研究這一點。 – 2011-02-23 08:15:41