CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 1999
    Location
    Montreal, Quebec, Canada
    Posts
    192

    Bad DLL Calling Convention, please help..

    I'm not a VB Expert, but I would like to know what the hell is the error here.

    My C++ DLL is declared this way:


    extern "C" __declspec(dllexport) int PublishPDF(int Version, LPSTR source, LPSTR destination, int delai);




    And my VB declare is:


    private Declare Function PublishPDF Lib "PubPDF" (byval Version as Integer, byval Source as string, byval Destination as string, byval Delay as Integer) as Integer




    And Visual Basic returns me a "bad calling convention" error (runtime error #49).. this is only happening at design time.

    Thank you in advance, I'm lost here...!



    ---
    Nicolas LeBlanc
    Software Engineer
    Ordiplan Inc.

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

    Re: Bad DLL Calling Convention, please help..

    2 things:
    - you need to specify _stdcall calling convention
    - you have to take into account, that in a 32 bit OS a C int is 4 Bytes, but a VB Integer is 2 bytes.
    Thus change your VB declare from "AS Integer" to "As Long"


  3. #3
    Join Date
    Jul 1999
    Location
    Montreal, Quebec, Canada
    Posts
    192

    Re: Bad DLL Calling Convention, please help..

    Yes, I added the stdcall but I noticed then my DLL wasn't working. And then I finally found the answer to my problems that nobody told me yet.

    I'm going to write about it for people searching the messages to answers about this...

    When you have a dll function that uses the "_stdcall", you *NEED* to declare this function into your .DEF file.. otherwise your function won't have an entry point. If you don't use the _stdcall, you will have access to your functions, but in Visual Basic, you'll have a bad calling convention.


    I'm getting to learn about DLL just as they're being replaced by OCX ;-)

    BTW, thanks for the 2 vs 4 bits integer, I didn't know about this one. I had one of my variables set as a long in VC++, what would that be then in VB?


    ---
    Nicolas LeBlanc
    Software Engineer
    Ordiplan Inc.

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

    Re: Bad DLL Calling Convention, please help..

    >I had one of my variables set as a long in VC++, what would that be then in VB?

    "...As Long" would be OK.



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