Hi all,
I'm trying to work out my first DLL (my first anything in C other than hello world). My intent is to call a DLL function, including arguments, from VB (in which I am quite versed).
I've been able to create a DLL which returns a specified value to the external caller, but I am running into trouble trying to send argument values. I've attempt to read up on the various methods to do so, including __declspec(dllexport), __stdcall, creating .def files (these I have not been able to successfully compile using bloodshed Dev-C++).
This works to return the value of 155 to the external caller:
1 2 3 4
|
extern "C" __declspec(dllexport) int MyFunc()
{
return 155;
}
|
I can add arguments to this function and compile:
1 2 3 4
|
extern "C" __declspec(dllexport) int MyFunc(int a, int b)
{
return a + b;
}
|
... but when I call this from VB I get a "bad DLL calling convention" error (which is generally attributed to arguments not correctly matching the API requirements).
However, I can do the following:
1 2 3 4 5
|
extern "C" __declspec(dllexport) int MyFunc(int a, int b)
{
MessageBox(NULL, TEXT("msg"), TEXT("title"), NULL);
return a + b;
}
|
... I call this from VB, passing the a and b parameters, and it fails (bad DLL calling convention again) only after displaying the MessageBox. I would feel safe saying that it fails at the first point that one of the function parameters is used.
For the life of me, I cannot seem to figure this one out. I did some reading on MSDN concerning __stdcall, __thiscall and __cdecl, and surmise that there may be some problem with the arguments being placed in the stack? I'm not sure.
Many thanks in advance for any input that could be given on the topic. I've searched for information online, but have found a bunch of examples that I have gotten to work no better than described above, and have not been able to find anything that I can make sense of concerning the passing of arguments to an exposed DLL function.
Cheers,
Jack