Casting IntPtr to COM Interface
Hello, can anyone tell me how to cast IntPtr to a COM Interface?
I'm obtaining a pointer to an IShellFolder interface using SHGetDesktopFolder:
Code:
Dim sfiRoot As IntPtr = IntPtr.Zero;
Dim hresult As Integer = ShellAPI.SHGetDesktopFolder(sfiRoot);
Now I want to get an IShellFolder instance out of this pointer.
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:
Code:
interface IExample
...
Dim ptr As IntPtr = SomeGetPointerMethod();
Dim inst As IExample = ???? ' cast ptr to IExample
Thank you.
Re: Casting IntPtr to COM Interface
Re: Casting IntPtr to COM Interface
Quote:
Originally Posted by
.paul.
I looked, there appears to be 2 candidates:
GetTypedObjectForIUnknown and GetObjectForIUnknown, will try both. Thank you.