CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: DLL Problem

  1. #1
    Join Date
    Feb 2000
    Posts
    7

    DLL Problem

    I have a problem linking a VB app to a C++ Win32 DLL. The dll exports a simple function. The header in the cpp file looks like
    this

    #ifdef TESTDLL2_EXPORTS
    #define TESTDLL2_API __declspec(dllexport)
    #else
    #define TESTDLL2_API __declspec(dllimport)
    #endif

    extern "C" TESTDLL2_API int fnTestdll2(int x);

    I'm trying to use this test dll from a VB app in which I have declared the function like so
    Private Declare Function fnTestdll2 Lib "Testdll2" _
    (ByVal val As Integer) As Integer

    Whenever I try to use the function I get a runtime error '49' saying 'Bad calling convention'. I've tried changing the values to long and get the same result.
    If I make the function void it works from the VB client if I use the function without passing a parameter. Does anyone know how to fix this?



  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: DLL Problem

    Try changing the line :

    >Private Declare Function fnTestdll2 Lib "Testdll2" _
    >(ByVal val As Integer) As Integer

    To :

    Private Declare Function fnTestdll2 Lib "Testdll2" _
    (ByVal val As Long) As Long



    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: DLL Problem

    whenever I write a C DLL for VB I do the following:
    - use stdcall calling convention
    - use a module definition file for all exported entries
    - use "As Long" for all C "int"s


  4. #4
    Join Date
    Feb 2000
    Posts
    7

    Re: DLL Problem

    I've tried Private Declare Function fnTestdll2 Lib "Testdll2" _
    (ByVal val As Long) As Long
    and still get the same problem.



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

Featured