sllynn2020
asked on
Getting and Object from a handle passed from a System DLL
Hi!
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,
PST_PROVIDERID* pProviderID,
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?
Thanks,
Scott
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,
PST_PROVIDERID* pProviderID,
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?
Thanks,
Scott
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well,
Thank you both for your suggestions.
AlexFM, To call CreateType, CreateSubtype, you need an instance of IPStore (actually the CPStoreClass implements the IPStore interface thus needing and instance of CPStoreClass). To do this, you need to call PStoreCreateInstance. If you call New, you get an Object, but not a CPStoreClass object since none of the classes have New functions.
PTakja, I tried your suggestion, but all it did was give me an error about DirectCast needing a reference but hPS being a value.
I've actually solved this problem by writing a simple standard Windows DLL that does all the work that I would have done to create the types as needed and the item in the PStore. (AlexFM's suggestion.)
Thanks,
Scott
Thank you both for your suggestions.
AlexFM, To call CreateType, CreateSubtype, you need an instance of IPStore (actually the CPStoreClass implements the IPStore interface thus needing and instance of CPStoreClass). To do this, you need to call PStoreCreateInstance. If you call New, you get an Object, but not a CPStoreClass object since none of the classes have New functions.
PTakja, I tried your suggestion, but all it did was give me an error about DirectCast needing a reference but hPS being a value.
I've actually solved this problem by writing a simple standard Windows DLL that does all the work that I would have done to create the types as needed and the item in the PStore. (AlexFM's suggestion.)
Thanks,
Scott
Dim Pstore As IPStore = DirectCast(hPS, IPStore)