Results 1 to 4 of 4

Thread: Run-Time Error 49: Bad Dll calling Convention

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Connecticut
    Posts
    135

    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.

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Connecticut
    Posts
    135

    Re: Run-Time Error 49: Bad Dll calling Convention

    That did not solve it

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width