3 Replies - 2190 Views - Last Post: 17 March 2013 - 10:13 PM Rate Topic: -----

#1 nivek25  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-March 13

error and problem on callback function using api in vb6

Posted 14 March 2013 - 09:33 PM

Im using vb6 to call a device API which in c language .dll and it has a callback function from the device to fire event. The device API code as follows:

this is the callback function:
typedef void(__stdcall * T_OperationMethod) (LONG32 Id, LONG32 operation, LONG32 result, LONG32 summary, void *data)

typedef void(__stdcall * T_StaMethod) (LONG32 status, LONG32 result, LONG32 summary, void *details)

typedef void(__stdcall * T_InterMethod) (LONG32 Id, LONG32 operation, LONG32 summary, void *data)




this is the API command with the callback function as parameter:
typedef signed long INT32 

typedef INT32 T_Result

DLL_API T_Result CALLTYPE test_Open(T_OperationMethod  	operation, 
				    T_StaMethod 	status,
				    T_InterMethod 	intermediate
	   	                   )	



Parameters:
[in] operation Callback function for operation event.
[in] status Callback function for status event.
[in] intermediate Callback function for intermediate event.




What i have done in Vb6 is as follows to equivalent the code above for enable me to call the API and also the callback function:

Function that i created for the api to callback:
Public Sub onOperation(ByVal Id&, ByVal operation&, ByVal result&, ByVal summary&, ByRef data As Long)

Public Sub onStatus(ByVal status&, ByVal result&, ByVal summary&, ByRef details As Long)

Public Sub onIntermediate(ByVal Id&, ByVal operation&, ByVal summary&, ByRef data As Long)




API command Delcaration equivalent to the C:
Public Declare Function test_Open Lib "testCtlW32.dll" (ByVal operation As Long, ByVal status As Long, ByVal intermediate As Long) As Long




Passing address of the callback function:
Dim lngReturn as long
lngReturn = bnr_Open(AddressOf onOperation, AddressOf onStatus, AddressOf onIntermediate)




However, I encounter error as the application crashed and it seem like my callback function is not working at all where by the function parameter or the function is not been called. Is there anything that i missed out?or the implementation of callback function i had done is wrong?

I had try to change the data type and also byval/byref change but it seem nothing is working.

When the application crashed the event viewer put this description as follows:

Faulting application project1.exe, version 1.0.0.0, faulting module msvbvm60.dll, version 6.0.98.2, fault address 0x000e47f2.

Thank You in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: error and problem on callback function using api in vb6

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: error and problem on callback function using api in vb6

Posted 17 March 2013 - 12:30 PM

I'm a bit suspicious of the return value in your Declare statement, but don't know enough C++ to be able to tell you why. For example, you might not have DLL_API defined properly. You might want to try posting in the C++ forum.
Was This Post Helpful? 0
  • +
  • -

#3 nivek25  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-March 13

Re: error and problem on callback function using api in vb6

Posted 17 March 2013 - 05:50 PM

Hi Bob,

Thanks for the advice, It might the data type been define wrongly as well. I would try out and see.Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: error and problem on callback function using api in vb6

Posted 17 March 2013 - 10:13 PM

All the VB looks ok. As for the return value, T_Result should translate to Long, since both int and long in C++ are Long in VB.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1