Getting a bad calling convention when calling a DLL from C++ with a long as parameter, yet it works fine for other functions!
C++ code for the DLL
extern "C" MY_API void SetCallBackStatusNotify(FARPROC theCallBack);
extern "C" MY_API void SetCallBackStatusNotifyA(long theCallBack);
Module code in VB
Declare Function SetCallBackStatusNotifyA Lib "C:\x\y.dll" (ByVal func As Long)
Public Function callBackStatus(stype As Integer, sid As Integer)
MsgBox "woot"
End Function
Public Function FARPROC(x As Long) As Long
FARPROC = x
End Function
Calling Code in Visual Basic form
Dim l As Long
l = FARPROC(AddressOf callBackStatus)
Call SetCallBackStatusNotifyA(l)
Any help would be great!
Try:
Declare Sub SetCallBackStatusNotifyA Lib "C:\x\y.dll" (ByVal func As Long)
the problem was the __stdcall && __cdecl problem so it only worked when running from compiled code not the IDE. however, now, when it calls back to a function callbackStatusNotify(ByVal x as long,ByVal y as long) there is a memory access problem.
tried changing byval/byref but no joy.
Quote from: gameschild on December 09, 2004, 04:25 AM
the problem was the __stdcall && __cdecl problem so it only worked when running from compiled code not the IDE. however, now, when it calls back to a function callbackStatusNotify(ByVal x as long,ByVal y as long) there is a memory access problem.
tried changing byval/byref but no joy.
Show us callbackStatusNotify() code?
Quote from: gameschild on December 09, 2004, 04:25 AM
the problem was the __stdcall && __cdecl problem so it only worked when running from compiled code not the IDE. however, now, when it calls back to a function callbackStatusNotify(ByVal x as long,ByVal y as long) there is a memory access problem.
tried changing byval/byref but no joy.
I have never heard of __stdcall vs __cdecl having a solution in compiling the code. I do know that it typically fails if you tell it that the function will return a Variant instead of telling it it will return nothing at all.