tags:

views:

298

answers:

2

Hi:

I have a simple DLL written with VC6 with one function:

__declspec(dllexport) int myfunc(long a, unsigned char *b, unsigned char *c, unsigned char *d, unsigned char *e)

And im calling it from vb6 using:

Declare Function myfunc Lib "mylib.dll" (ByVal a As Long, ByVal b As String, ByVal c As String, ByVal d As String, ByVal e As String) As Long

....

dim a as long
dim b as string
dim c as string
dim d as string
dim e as string
dim r as long

r=myfunc(a,b,c,d,e)

Im getting "bad dll calling convention" error but I cant figure out why. Any ideas?

Regards

+3  A: 

Generally speaking, 'bad DLL...' means what it says. VB6 requires the _stdcall convention (like the Win API) for any external functions it calls.

Try adding __stdcall to the C function prototype and see what happens.

Jim Mack
A: 

Check out the Universal DLL function caller, by Paul Caton:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=70195&lngWId=1

It will allow you to call pretty much any type of function from VB6.

Joe