language >> DLL function declaration problem

by Joshua Ellul » Sat, 11 Oct 2003 20:26:10 GMT

Hi There,

I have created a DLL in C++. A particular DLL function works fine when
called from a C++ program, however when trying to call the same DLL function
in VB an error is recieved 'Bad DLL Calling Convention'

The function is exported in the DLL as follows:
EXPORT void StartKeyboardHook(LRESULT (*)());

and imported in the VB application as follows:
Public Declare Sub StartKeyboardHook Lib "HooksLIB.dll" (ByVal CallBackFunc
As Long)

The function is then called in vb as follows:
Call StartKeyboardHook(AddressOf KeyPressed)

Any ideas?


language >> DLL function declaration problem

by Kobi Ben Tzvi » Sat, 11 Oct 2003 20:45:35 GMT



I think you are missing '__stdcall' before your function declaration.

EXPORT __stdcall void StartKeyboardHook(LRESULT (*)());

Kobi Ben Tzvi


Similar Threads

1. Is friend function declaration also function declaration?

2. figuring out c# declarations from a DLL of C functions


I'm trying to use a C function ( long int myFunc() ) from a DLL in my
C# program. I use DllImport("dllname") a C function and declare it as

public static extern int myFunc();

At first I used 

public static extern long myFunc();

but that returned a bizarre value.  I incorrectly assumed a C long int
to C# long.   Using C# int worked.   But here's my question -

Since the DLL is known, is there a tool that will list the C#
equivalents for
the functions as long as the variable types are standard (i.e., int,
long, float, etc. )?  Does it seems reasonable that C# should be able
to gather this info from the DLL?

Finally, what is the name of the process of using the [DllImport...]
specification for loading external functions?
Is this PInvoke?
Are there any books/articles describing this in detail, particularly
accessing and running C functions that return pointers to structures.



3. VB6 function declaration from C++ dll - Visual Basic/VB

4. Variable declaration taken as a function pointer declaration

When compiling the following code:

#include <iostream>

struct B {};

struct A
  A(B b1, B b2) {};
  void foo() { std::cout << "foo called" << std::endl; }

int main(int argc, char * argv[])
  A a(B(), B());;
  return 0;

the compiler will interprete the first line of the main function as a
function pointer declaration, and thus will fail at the next line. Does
somebody know why this is so, and if there is an elegant way to solve
this problem that does not involve temporary variables?


5. Function declaration in class declaration

6. class declarations in function declarations

7. class declaration within friend function declaration

8. Defect Report: Using declaration cannot be a function declaration