Getting and Object from a handle passed from a System DLL
Posted on 2005-04-28
I'm trying to interfae with the PStore dll in VB.NET. Adding it as a reference works except, it doesn't make the PStoreCreateInstance function available. You need to call this to get an instance of the PStore object. Using "new" on the object class doesn't seen work, so I'm assuming this function still needs to be called.
It has the following interface in C:
HRESULT PStoreCreateInstance( IPStore** ppProvider,
void* pReserved, DWORD dwFlags);
So, I've defined the function as follows:
Private Declare Function PStoreCreateInstance Lib "pstorec.dll" (ByRef hPS As IntPtr, ByVal l1 As Long, ByVal l2 As Long, ByVal l3 As Long) As Integer (Only the first argument is necessary here.)
This works. I can see hPS has a value in the debugger, and the memory at that address looks like it could be the structure I need. However, I now need to get this memory location to represent an instance of CPStoreClass to use it.
Maybe I'm going about this the wrong way.
What is the right way to get this object back from this function?