Click to See Complete Forum and Search --> : Passing parameters to a C DLL


Markmcdade
December 2nd, 1999, 08:30 AM
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.

Lothar Haensler
December 2nd, 1999, 08:36 AM
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