Run-Time Error 49: Bad Dll calling Convention
I am trying to call in into a c++ dll:
HTML Code:
GetLibInfo(LPCTSTR libName, long* numEntries, long* numPoints, HANDLE* hLibComment, double* firstX, double* lastX, DATAXTYPE* pxtype, DATAYTYPE* pytype, long* bBaseline, long* libIsATR, long* bReadonly, LIBBYTES* libBytes)
From the vb module, I did this:
HTML Code:
Public Declare Function GetLibInfo Lib "DLSLibSearch_ur.dll" (ByVal LibName As String, ByRef numEntries As Integer, ByRef numPoints As Integer, ByRef hlibComment As Integer, ByRef FirstX As Double, ByRef LastX As Double, ByRef DataXtype As Integer, ByRef DataYtype As Integer, ByRef bBaseline As Integer, ByRef libIsAtr As Integer, ByRef bReadonly As Integer, ByRef LibBytes As Integer) As Long
And when I call the function in a form, i get the error message
HTML Code:
Private Function getInfo(ByVal LibName As String) As Long
Dim numEntries As Integer
Dim numPoints As Integer
Dim hlibComment As Integer
Dim FirstX As Double
Dim LastX As Double
Dim DataXtype As Integer
Dim DataYtype As Integer
Dim bBaseline As Integer
Dim libIsAtr As Integer
Dim bReadonly As Integer
Dim LibBytes As Integer
Dim ret As Long
ret = GetLibInfo(LibName, numEntries, numPoints, hlibComment, FirstX, LastX, DataXtype, DataYtype, bBaseline, libIsAtr, bReadonly, LibBytes)
geInfo = ret
End Function
I am quite sure it is a conversion that is killing me.......Any suggestions/ideas from anyone will do.
Re: Run-Time Error 49: Bad Dll calling Convention
Code:
Public Declare Function GetLibInfo CDecl Lib "DLSLibSearch_ur.dll" ...
... may work compiled to native code but almost certainly not when run in the IDE.
That C++ library was compiled using C-style calling conventions that are not compatible with Visual Basic, which assumes StdCall as used by most Win32 APIs. A custom typelib might also be a workaround for a calling convention mismatch.
Re: Run-Time Error 49: Bad Dll calling Convention
Re: Run-Time Error 49: Bad Dll calling Convention
Well I didn't mean to imply it was a magic bullet. The CDecl keyword is ignored when you run the program within the IDE. It doesn't always work even when you compile to native code. It's also entirely undocumented, so you can't really expect much.
The real fix is to create a typelib to address the calling convention mismatch or else change the C++ library to use STDCALL and recompile it.