Click to See Complete Forum and Search --> : DLL Problem


VCGuy
February 8th, 2000, 09:32 AM
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?

Chris Eastwood
February 8th, 2000, 09:51 AM
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

Lothar Haensler
February 8th, 2000, 09:51 AM
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

VCGuy
February 8th, 2000, 10:08 AM
I've tried Private Declare Function fnTestdll2 Lib "Testdll2" _
(ByVal val As Long) As Long
and still get the same problem.