Results 1 to 9 of 9
  1. #1
    mujaqo is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2008
    Posts
    13

    Unhappy runtime error 49 bad dll calling convention

    Please help, I have tried all possible ways to load the attached dll library and use it to perform two simple functions, first "PortOpen" and second to "DisplayText", I have attached the user guide which came with the dll file but the code written in C++, i tried the following which got me error "runtime error 49 bad dll calling convention"
    Declare Function PortOpen Lib "VFD_DLL.dll" (ByVal PortName As String) As Long
    Declare Function DisplayText Lib "VFD_DLL.dll" (ByVal str As String) As Long
    Call PortOpen("COM1")



    and when changing the type i get runtime error 13 type mismatch.

    Please take a look at the attached file you might find something I missed.
    Attached Files Attached Files

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I looked at the instructions and it seems that PotOpen returns True or False. Sometimes this can fit into an integer but maybe it would be best to have your bucket as Boolean data type. How are you calling PortOpen from within your DB?


    Declare Function PortOpen Lib "VFD_DLL.dll" (ByVal PortName As String) As Boolean

  3. #3
    mujaqo is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2008
    Posts
    13
    I use Call PortOpen("COM1") in my form to call the function.
    I tried Declare Function PortOpen Lib "VFD_DLL.dll" (ByVal PortName As String) As Boolean and got the same error "runtime error 49 bad dll calling convention"

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I see. I missed that in your earlier post. The function does not cause the DLL to take an action. According to the directions it only returns a value. So, calling it won't provide any results. Seems like this is why you get the invalid call exception.

    Try this to test.

    msgbox PortOpen("COM1")

    It should return true or false, hopefully...

  5. #5
    mujaqo is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2008
    Posts
    13
    I tried msgbox PortOpen("COM1") and got the same error "runtime error 49 bad dll calling convention"

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I don't know. The instructions are not clear enough for my limited knowledge. I Use Dll's but I don't make my own so all I can do is guess.

    The only other thing I can think of would be to name your string just like the example in the instructions. I don't think it matters though.
    Declare Function PortOpen Lib "VFD_DLL.dll" (ByVal PortName As String) As Boolean

    The others things to consider are to get your DLL file(s) in the correct directory for your OS (system folder). Consider 32bit vs. 64bit. Might need to place it in the application folder so you can reference a dynamic directory to. In other words, use the full path when writing your functions.

    Also, you will probably need to load the file and create a handle. May need to do this before using the dll. Don't know, just guessing.

    Code:
    'You would have to create  functions so you can
    Declare Function LoadLibrary Lib "VFD_DLL.dll" (ByVal sFilePath as String) as Variant
    Declare Function FreeLibrary Lib "VFD_DLL.dll" (ByVal hDll as Double) as Long 'Or maybe boolean
    'how to load dll
    dim hDll as Double 'I beleive handles should be double
    hDll = LoadLibrary("VFD_DLL.dll") or maybe full path
    'how to release dll
    Call FreeLibrary(hDll)
    Hope this helps some. I just don't know enough about them to understand the instructions provided. I would look into the dynamic path thing if you stay stuck. Good Luck.

  7. #7
    mujaqo is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2008
    Posts
    13
    Thank you for your effort, I tried your suggestions and got runtime error '453' can’t find DLL entry point LoadLibrary in VFD_DLL.dll
    I think Declare Function PortOpen Lib "VFD_DLL.dll" (ByVal PortName As String) As Boolean is the right way to load the library but i feel the problem with Character and String conversion between C++ and VB, i tried to use Byte and got runtime error 13 Type mismatch.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Then maybe

    Declare Function PortOpen Lib "VFD_DLL.dll" (ByVal PortName() As Variant) As Boolean
    or
    Declare Function PortOpen Lib "VFD_DLL.dll" (ByVal PortName As Variant) As Boolean

  9. #9
    mujaqo is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2008
    Posts
    13
    Tried to use Variant and again the same error "runtime error 49 bad dll calling convention"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calling Error
    By drunkenneo in forum Programming
    Replies: 6
    Last Post: 09-12-2013, 01:32 PM
  2. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  3. Replies: 3
    Last Post: 05-02-2011, 12:08 PM
  4. Error in Runtime Only
    By drunkinmunki in forum Programming
    Replies: 7
    Last Post: 12-16-2010, 03:43 PM
  5. Syntax Error while calling sub: Expected: =
    By cowboy in forum Programming
    Replies: 3
    Last Post: 07-12-2010, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums