Thanks John,
After I removed extern C, it did compile to a DLL.
But I was wondering if you can help me some more.
I wish to call this from Visual Basic 6, and I found a link claiming certain things about VB6:
**********************************************************
http://www.mingw.org/MinGWiki/index.php/VB-MinGW-DLLExample 1: A DLL for Visual Basic, Programmed in C or C++
NOTE : This description is only for Visual Basic 6, not DotNet.
* Step 1: Create your DLL.
VB can only call __stdcall functions, not __cdecl functions. So we must export all our functions as __stdcall. Create a DLL with the following code template:
extern "C" // only required if using g++
{
__declspec (dllexport) void __stdcall FooBar (void)
{
return;
}
__declspec (dllexport) DWORD __stdcall FooBarRet (DWORD MyValue)
{
return MyValue;
}
__declspec (dllexport) BOOL __stdcall DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
} // extern "C"
When compiling, add "--add-stdcall-alias" to your linker flags. If you're passing linker flags via g++, it should be "-Wl,--add-stdcall-alias". This adds an undecorated alias for the exported function names that is simply the name of the function. By default, the functions are exported with an @nn appended to the function name.
The DllMain function is called by the system when your dll is loaded and unloaded from a process, as well as when threads attach and detach (I'm not sure what that means, but it's in the case statement). If you have anything important to do in your dll when these events occur, this is the place to do it. Initializing WinSock is a popular thing to do here so that the WinSock function calls don't all return 10093 -- WSANOTINITIALISED. If you don't export this function yourself, it won't be automatically exported as in Visual Studio.
* Step 2: Call DLL from VB
Under VB, create the library call such as:
Private Declare Sub FooBar Lib "mydll" ()
Private Declare Sub FooBarRet Lib "mydll" (ByVal MyValue As Long) As Long
That's all. As an alternative, you can create a TypeLib, but that's another story.
*************************************************************************************************************
My Questions and comments below :
1) They claim that my function prototype has to be pre-fixed with:
__stdcall
For use with VB6, do you (or anybody) know this to be the case?
2) Also I have noticed on the internet, that some code uses one Underscore and more of them use two Underscores:
I used : _declspec
Others above : __declspec
What is the reason for the difference in number of underscores?
3) Due to your suggestion of a wizard, I did find it.
Thanks. Took some time though to analyze, I found it confusing until I looked at the Wizard.h file
Thanks again John really appreciated your input!!!
Paul