Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Problems with callback from DLL invoked from VBA
I have to invoke a C++ function from VBA/Excel that does a callback. I've
isolated the problem I'm having in the code below. In the C++ (complied & linked to a DLL) I have: long __stdcall tryCB3(long n, long (*cbFunc)(long m)) { long r; r = cbFunc(n); // call back return r; } In the VBA I have: Private Declare Function tryCB3 Lib "SparkExUtilsDll.dll" _ (ByVal n As Long, ByVal theFunct As Any) As Long Public Function theCBFunc3(ByVal m As Long) As Long Debug.Print "In theCBFunc3" theCBFunc3 = m * m End Function Public Function tryCBDrv3() Dim n As Long Dim q As Long n = 2 q = tryCB3(2, AddressOf theCBFunc3) Debug.Print "n= " & CStr(n) Debug.Print "q= " & CStr(q) End Function When I step through tryCB3Drv it calls tryCB3, and then steps through theCBFunc3, all working as expected, but then crashes with a C++ error dialog saying the ESP was not preserved through a function call etc. Note that the it works without crashing if the callback function has no arguments, so it must be some problem with the way VBA is setting up the argument to theCBFunc3, vs. the way it's declared in C++. Any ideas? TIA Ed |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
More than one copy of EXCEL 2003 invoked | Excel Discussion (Misc queries) | |||
Customized Menu Macro with Argument invoked twice | Excel Programming | |||
Using Excel to handle Com callback procedures | Excel Programming | |||
RTD Callback and CIS with firewall | Excel Programming | |||
The object invoked has disconnected from its clinets | Excel Programming |