
Calling int f(int (*f)(int)) like function in DLL from VB
Quote:
>Hi,
>I use VC++'s Win32 DLL Wizard to create a DLL with these things:
>// IN .CPP
>int (*f1)(int);
VB uses __stdcall calling convention only.
This is pointing to a default calling convention function (__cdecl).
The pointer you are assigning to it is a VB function, therefore
__stdcall.
Change the declaration to:
LIBRARY_API int (*f1)(int);
Then change
#define LIBRARY_API __declspec(dllimport)
to
#define LIBRARY_API __declspec(dllimport) __stdcall
(I think that's right; I still use DEF files to avoid name
mangling)
<snip>
Quote:
>Then VB says it cannot find the entry point.
Right. The names are mangled. You have to either use
a DEF file or reference the decorated name in the Alias
clause of your function declaration in VB. Either way
works fine.
Quote:
>I try adding a DEF file to the
>VC project, this time, VB says the calling convention is bad.
Because it is. If you use the DEF file to avoid the name,
change LIBRARY_API to just __stdcall. You really only
want to use either __declespec( dllimport | dllexport )
or the DEF file, not both.
But for interaction with VB, __stdcall is mandatory.
Quote:
>What should I
>do? Furturemore, since Win32 DLL wizard didn't create a DEF file for me, is
>it really unnecessary?
It's unnecessary unless you need to change the default behavior
of the compiler (like name decoration).
Quote:
>--
>Wang Weijun
>wangwj at taslon dot com | wangwj at iname dot com