Callback to a VB function 
Author Message
 Callback to a VB function

From a VB program, I am passing a function pointer to a
function in a C++ dll.  The C++ function calls my VB
callback function just fine.  After control returns to my
C++ function, the application crashes.  I suspect that
this has something to do with calling conventions, and
that the stack is being handled improperly.  Sample code
for my C++ function is below:

extern "C" __declspec(dllexport) long WINAPI
DoSomethingWithCallback(long TheNum,
          long (*  CallbackPtr)(long))
{
    long RetVal;
    RetVal = (* CallbackPtr )(TheNum);
    return RetVal;

Quote:
}

Please help!


Sun, 06 Jun 2004 04:49:35 GMT  
 Callback to a VB function
Try typefeding callback as __stdcall:

typedef long (WINAPI *CallbackPtr_t)(long);

extern "C" __declspec(dllexport) long WINAPI
DoSomethingWithCallback(long TheNum,
          CallbackPtr_t CallbackPtr)
{
    long RetVal;
    RetVal = CallbackPtr(TheNum);
    return RetVal;

Quote:
}

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> From a VB program, I am passing a function pointer to a
> function in a C++ dll.  The C++ function calls my VB
> callback function just fine.  After control returns to my
> C++ function, the application crashes.  I suspect that
> this has something to do with calling conventions, and
> that the stack is being handled improperly.  Sample code
> for my C++ function is below:

> extern "C" __declspec(dllexport) long WINAPI
> DoSomethingWithCallback(long TheNum,
>           long (*  CallbackPtr)(long))
> {
>     long RetVal;
>     RetVal = (* CallbackPtr )(TheNum);
>     return RetVal;
> }

> Please help!



Sun, 06 Jun 2004 04:58:41 GMT  
 Callback to a VB function

Quote:
> From a VB program, I am passing a function pointer to a
> function in a C++ dll.  The C++ function calls my VB
> callback function just fine.  After control returns to my
> C++ function, the application crashes.  I suspect that
> this has something to do with calling conventions, and
> that the stack is being handled improperly.  Sample code
> for my C++ function is below:

Try changing this line

    long (*  CallbackPtr)(long))

to

    long (CALLBACK *  CallbackPtr)(long))

Regards,
Will



Sun, 06 Jun 2004 05:09:40 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VB callback function, called from a VC DLL, crashes

2. Return values from VB CallBack Function to VC Dll

3. CALLBACK, CALLBACK, CALLBACK?

4. Passing "callback" function to a function

5. Getting pointer to non-static member function from C callback function

6. Passing C++ Class Member Function to as a C Callback Function Parameter

7. Callback function/function pointer question

8. Callback functions as member functions

9. Calling C++ member function through C function callback

10. class member function as callback function

11. How to use member function of a C++ class as a callback function

12. Using Non-Static Callback Functions as member Functions VC5.0

 

 
Powered by phpBB® Forum Software