-
DLL Problem
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?
-
Re: DLL Problem
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
-
Re: DLL Problem
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
-
Re: DLL Problem
I've tried Private Declare Function fnTestdll2 Lib "Testdll2" _
(ByVal val As Long) As Long
and still get the same problem.