-
Library Linking problem
I'm having problems with statically linking to a DLL with the mingw compiler in DEV C++. I have the .a(generated when compiling the DLL) file in directory my .exe is in and the .h file from the DLL in the \Include directory and the .exe does not import the DLL and so I cannot access the functions as required. I know it does not import it cos it's not included on the import table when I open the .exe with Quick View.
Any help would be much appreciated!!
-
when you linked the dll, did you create a def file? Use quickview to list the export table (or better do this with dependancy walker if you have it)
when you linked the exe did you actually add the dll's library to the project?
-
Fordy,
The DLL is fine as far as I can tell-there is an export table with all my functions. I have used this DLL already with HP-VEE and it worked fine.
As for the library goes I placed it in the project folder(if thats what your asking me) and the header file in the \include folder. To link all I have to do then is:
#include <cdll.h> /*My header file*/
{
.......Rest of program
}
Am I correct in that?
The header file included the same one used to compile the DLL?
What do I have to do with the .def file?
-
The library created with the dll is the import library...it tells the linker what the program expects to import......I'm suprised the project links without this library being added to the exe...
The def file is created with the dll project like so
Code:
LIBRARY MyDll
EXPORTS MyExportedFunc
and it tells the linker which functions to add to the dll's export table. I dont know how Devc++ uses def files......I do all my dlls with the Microsoft Linker in VC++ or MASM32 (VC++ has a better method than defs....__declspec(dllexport))......with that linker, if you used a def file you would add def file with the params you send when linking
Ok...if you are sure the dll is fine.....try this
Say the function you are exporting is declared like
int MyExportedFunc(int);....
Adapt this pseudocode and put it in your code
Code:
typedef int (MYEXPORTEDFUNC*)(int);
MYEXPORTEDFUNC lpfMyExportedFunc;
HMODULE hMod = LoadLibrary("MyDll.dll");
if(!hMod){
Errorhandler();
return;
}
lpfMyExportedFun =
(MYEXPORTEDFUNC)GetProcAddress(hMod,"MyExportedFunc");
if(!lpfMyExportedFun){
Errorhandler();
return;
}
/*Use func*/
int nRes = lpfMyExportedFunc(50);
FreeLibrary(hMod);
lpfMyExportedFunc = NULL;
Here you are loading the dll at runtime and finding where the function you need is...then you are assigning it to a function pointer and then calling it.
I havent tested the above, but all those functions are on MSDN