|
-
March 21st, 2001, 12:29 PM
#1
VB Crash after callback function is called
Hello all,
Ultimately I'm writing a VB interface to a message broker written in java. The message broker has a C API that I'm using to interface to. My problem is that I've written a callback function in VB (it's in a standard module) and passed the address to the C API. Everything works great. I even get the callback telling me I have a message. However, for some reason, the VB development environment keeps crashing everytime the callback function is called. I've place Debug.Print statements in the callback and they all execute so I know the callback does its thing and leaves.
The error I get is "The instruction at "blah" referenced memory at "blah". The memory could not be "read".
The strange things is that the instruction address and the memory location address are the same.
I activate the callback from a form that pushes data to the message broker who in turn sends it back to me.
Any ideas on why the VB environment keeps crashing?
Thanks,
Kenny
-
March 21st, 2001, 12:43 PM
#2
Re: VB Crash after callback function is called
It sounds as if the heap (or instruction) pointer is in the wrong place after the call.
What's the expected return type of the C prototype callback?
If its a VOID your callback must be a Sub(), if its INT your callback must be a Function() As Long etc.
Double check this. If unsure, post us the prototype, e.g. 'typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM); and we'll see what we can come up with.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
-
March 21st, 2001, 12:57 PM
#3
Re: VB Crash after callback function is called
Thanks for the reply. The expected return type is an int. Here is the prototype:
typedef int (*ohMsgHandlerFunction)(ohContext, ohSession, ohEnvelope, void *)
where ohContext, ohSession, and ohEnvelope are defined as void*
Here is my function:
Public Function GPS_MessageHandler(ByVal context As Long, _
ByVal session As Long, _
ByVal envelope As Long, _
ByVal usercontext As Long) As Long
On Error Resume Next
GPS_MessageHandler = 0
End Function
I'm stumped 
-
March 21st, 2001, 01:14 PM
#4
Re: VB Crash after callback function is called
The only thing I can think of is that your callback is passing pointers (i.e. call by reference) but you are reading them as ByVal. Maybe try:
public Function GPS_MessageHandler(context as Long, _
session as Long, _
envelope as Long, _
usercontext as Long) as Long
on error resume next
GPS_MessageHandler = 0
End Function
Then use IsBadReadPtr() before using those values to prevent any crashes.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|