Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting and Object from a handle passed from a System DLL

Posted on 2005-04-28
3
Medium Priority
?
472 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:sllynn2020
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 1000 total points
ID: 13883983
IPStore* pointer filled by PStoreCreateInstance function is pointer to interface. You need to call interface functions like CreateType, CreateSubtype etc. What is CPStoreClass that you expect to be pointed by IPStore?
I have never worked with these functions, but maybe I can give some direction. For example, if you know memory structure pointed by IPStore*, you can use Marshal class functions to extract information from it.
I beleive it is better to do in unmanaged C++ code, but possibly there ib VB .NET solution.
0
 
LVL 14

Expert Comment

by:ptakja
ID: 13884233
I wouldl try the DirectCast function. It has the following syntax,

Dim Pstore As IPStore = DirectCast(hPS, IPStore)
0
 

Author Comment

by:sllynn2020
ID: 13892224
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
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question