Link to home
Start Free TrialLog in
Avatar of wym
wym

asked on

Calling a C dll function with VB

I have written a C dll that exports functions that return LPXXX variables.  

Eg:

LPMAPISESSION __stdcall GetSession();
void  __stdcall CloseSession(LPMAPISESSION);

I want to be able to call these functions from VB, so I declared them like this:

Private Declare Function GetSession Lib "lgkmapi.dll" () As Long
Private Declare Function CloseSession Lib "lgkmapi.dll" (ByVal lpSession As Long)

Private Sub Command1_Click()

Dim lpSession As Long

lpSession = GetSession()
MsgBox lpSession
CloseSession (lpSession)
End Sub

My problem is that I'm crashing on the CloseSession function.  

I debug it through VC and I see that the value of lpSession returned from GetSession is 0x0168f108.  From VB, the message box shows 23654664 was returned, which is the equivalent of 168f108 in hex.

When I debug the CloseSession function in VC, I see that I'm actually passing in 0x0063f3e8 for lpSession.  How'd this happen?  I have tried passing lpSession ByRef and ByVal in CloseSession but neither works.  

Can anyone help solve this?

ASKER CERTIFIED SOLUTION
Avatar of SimonRodan
SimonRodan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ark
What is typedef for LPMAPISESSION?
Avatar of wym
wym

ASKER

Well, I found my problem was the fact that I was using an older version of my dll (in the same folder as my VB exe) and I should have given it an absolute path of my debug folder in my VC project when I stepped through in VC.  (DOH!)  But, I'm giving you the points because I learned something new about the dos prompt dumpbin which was neat.