1 Replies - 5767 Views - Last Post: 18 March 2013 - 03:37 PM Rate Topic: -----

#1 nivek25  Icon User is offline

  • New D.I.C Head

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

Win32 API in C (having error in call back function by using vb6)

Posted 17 March 2013 - 05:52 PM

Im using vb6 to call a device API(WIN32) 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:
**Each of last parameter (void *data/details) carry a pointer which contain data structure.

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 that i wish to call 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 Description:
[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:

i had create sub procedure for the api to callback as callbackfunction:
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.

Any Advice?Is it any crash in the memory address location?due to wrong parameter data type or my method calling (call back function "address of" is wrong)

Thank You in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Win32 API in C (having error in call back function by using vb6)

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1311
  • View blog
  • Posts: 4,503
  • Joined: 19-February 09

Re: Win32 API in C (having error in call back function by using vb6)

Posted 18 March 2013 - 03:37 PM

I'm not sure what CALLTYPE resolves to so I would try WINAPI or __stdcall instead.

5   DLL_API T_Result CALLTYPE test_Open(T_OperationMethod operation,
    ...


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1