R – How to use the .def file for explicit linking

dllfunctionlinkervisual-studio-2005

I am facing the the problem to link to a third party dll. It is windows mobile application, where I am try to link to this third party dll.

Here first I had the dll and lib file. I was not able to link to it explicitly, but implicit linking is working. In the explicit linking the getprocaddress was failing. The dumpbin showed only the dllmain functions being exposed and no other function being exposed, hence the getprocaddress was failing.
However my application doesnot start if the dll is not found/installed in the device. It is expected as it is imlicit linking of a dll hence my application does not start.

I reported this to the third party dll provider and said that I want the explicit linking as the dll takes more space in my application if it is linked implicitly.
They replied by providing the .def file and said that I can use this .def file in my app to explicitly link to a dll.

I don't know how to use this .def file to explicitly link to a dll. Can any one please explain briefly about how to use this .def file in my app to explicitly link to a dll.

Best Answer

Use the *.def file when you build the DLL, to specify what function names the DLL is supposed to export.

After the DLL is built, use dumpbin /exports to verify that the functions are indeed exported from the DLL.

After you have verified that the DLL is exporting functions, you can either link to them at run-time using LoadLibray/GetProcAddress, and/or you can link to them at build-time by passing the DLL's *.lib file (which was created when you built the DLL using its *.def file) as an argument to your application's linker.