Valhalla Legends Forums Archive | Visual Basic Programming | VB -> DLL Sending Function Pointer [Bad Calling Convention]

AuthorMessageTime
gameschild
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
[code]
extern "C" MY_API void SetCallBackStatusNotify(FARPROC theCallBack);
extern "C" MY_API void SetCallBackStatusNotifyA(long theCallBack);
[/code]

Module code in VB
[code]
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
[/code]

Calling Code in Visual Basic form
[code]
Dim l As Long

l = FARPROC(AddressOf callBackStatus)
Call SetCallBackStatusNotifyA(l)
[/code]

Any help would be great!
December 6, 2004, 10:59 AM
Adron
Try:
[code]Declare Sub SetCallBackStatusNotifyA Lib "C:\x\y.dll" (ByVal func As Long)[/code]
December 6, 2004, 3:43 PM
gameschild
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.
December 9, 2004, 10:25 AM
kamakazie
[quote author=gameschild link=topic=9796.msg91615#msg91615 date=1102587919]
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]

Show us callbackStatusNotify() code?
December 9, 2004, 10:40 AM
Adron
[quote author=gameschild link=topic=9796.msg91615#msg91615 date=1102587919]
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]

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.
December 9, 2004, 1:10 PM

Search