Hello, can anyone tell me how to cast IntPtr to a COM Interface?
I'm obtaining a pointer to an IShellFolder interface using SHGetDesktopFolder:
Now I want to get an IShellFolder instance out of this pointer.Code:Dim sfiRoot As IntPtr = IntPtr.Zero; Dim hresult As Integer = ShellAPI.SHGetDesktopFolder(sfiRoot);
I know that I can change the declaration of SHGetDesktopFolder's parameter to IShellFolder instead of IntPtr, but for a number of reasons I need to keep it as IntPtr, moreover, I get the feeling that I will need to cast pointers to interfaces and back several times.
Basically, I need to know what it takes to get an instance of an Interface from IntPtr and back - get the pointer (IntPtr) out of Interface instance:
Thank you.Code:interface IExample ... Dim ptr As IntPtr = SomeGetPointerMethod(); Dim inst As IExample = ???? ' cast ptr to IExample


Reply With Quote
