CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 1999
    Posts
    10

    Passing parameters to a C DLL

    I'm having trouble passing parameters in VB to a DLL which was created in C.
    returned values are ok if no parameters are passed, but the error:

    "Bad calling convention"

    appears each time I try to pass parameters

    my C function header is

    MYDLL_API int add(int x, int y)




    in VB, I have the line to link to the DLL as

    private Declare Function add Lib "mydll.dll" (byval f as Integer, byval s as Integer) as Integer
    option Explicit




    the function itself contains the lines

    txtAnswer.text = add(5,4)




    Any Idea?

    Thanks for any help.



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

    Re: Passing parameters to a C DLL

    IMHO you should consider the following changes:
    - a VB Integer is 2 bytes, a C int in 32-Bit-World is 4 bytes. Thus DECLARE the VB arguments "As Long"
    - use stdcall calling convention in your C declaration


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