Re: recompile a DLL with _stdcall for VB
<pink0.pallino@libero.it> wrote:
Could it be written in other way without the typedef
and keeping
the
"void (CALLBACK* amIReadyCallback)(int, LPVOID)"
as it was written in the original:
BOOL DLLEXPORT myfunctionCDECL(int nvalue, void (CALLBACK*
amIReadyCallback)(int, LPVOID), LPVOID lpvParameters)
{
// a lot of things here
}
and write a wrapper function with this?
just asking, I don't know if it is possible
Of course it's possible. The typedef is just a shortcut, so
you don't need to write all these ugly parentheses. So, in
the first part of my message you can see the code without
typedef. You're error was that you passed the type of a
parameter as well, insead of passing only parameter itself.
Consider following example:
void foo(int param1, double param2);
void bar(int param1, double param2)
{
foo(param1, double param2); // <-- Error!
}
The above implementation of `bar' will produce an obvious
error, since you don't need to specify parameter's type when
calling a function. You made this very mistake by passing
type of `amIReadyCallback' parameter. Here's your code:
BOOL STDDLLEXPORT myfunctionSTD(
int nvalue,
void (CALLBACK* amIReadyCallback)(int, LPVOID),
LPVOID lpvParameter)
{ //function wrapper for VB
BOOL value;
value= myfunctionCDECL( nvalue,(CALLBACK*
amIReadyCallback)(int,
LPVOID), lpvParameter); <---here I get the error
return value;
}
In order to avoid the error all you need to do is to pass
parameter correctly:
....
myfunctionCDECL(nvalue, amIReadyCallback, lpvParameter);
....
That's why I suggested to use typedef, since errors like the
above one is much easier to spot when type name is clear and
short. BTW, Platform SDK defines such type for TimerProc
callback exactly for this reason: to make code more
readable:
typedef VOID (CALLBACK* TIMERPROC)(HWND, UINT, UINT_PTR,
DWORD);
So, now you can use `TIMERPROC' name:
void foo(TIMERPROC pFunc)
{
...
pFunc(...);
}
Alex