Trying to call a C++ DLL from VBA (MS Access) and keep getting a 'bad dll calling convention' error, as well as MS Access crashing.
Here's the C++ API function I'm trying to call:
_IMPORT HRESULT _CONVENTION PCRSNewTrip (Trip *pTripID);
"Trip" is defined as:
typedef long Trip;
From the API header:
#if defined (__BORLANDC__)
#define _IMPORT __declspec( dllimport )
#define _CONVENTION __stdcall
#elif defined (_MSC_VER)
#define _IMPORT _declspec( dllimport )
#define _CONVENTION _cdecl
#endif
Here's a bit of info regarding the function: PCRSNewTrip() places a handle to the new trip in the pointer argument passed in (tripID). The return code is the same as all other DLL functions (used for error handling).
Here's my latest attempt at calling the function:
Public Declare Function PCRSNewTrip Lib "C:\xxx\pcrsrv32.dll" Alias "_PCRSNewTrip" (ByRef myTripPtr As Long) As Long
Private Sub NewTrip_Click()
Dim myTrip As Long
Dim myTripPtr As Long
myTripPtr = VarPtr(myTrip)
myTrip = PCRSNewTrip(myTripPtr)
EndSub
I'm getting a "Bad DLL calling convention" error.