Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: gameschild on December 06, 2004, 04:59 AM

Title: VB -> DLL Sending Function Pointer [Bad Calling Convention]
Post by: gameschild on December 06, 2004, 04:59 AM
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!
Title: Re: VB -> DLL Sending Function Pointer [Bad Calling Convention]
Post by: Adron on December 06, 2004, 09:43 AM
Try:
Declare Sub SetCallBackStatusNotifyA Lib "C:\x\y.dll" (ByVal func As Long)
Title: Re: VB -> DLL Sending Function Pointer [Bad Calling Convention]
Post by: 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.
Title: Re: VB -> DLL Sending Function Pointer [Bad Calling Convention]
Post by: dxoigmn on December 09, 2004, 04:40 AM
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?
Title: Re: VB -> DLL Sending Function Pointer [Bad Calling Convention]
Post by: Adron on December 09, 2004, 07:10 AM
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.