Exporting a function from a DLL in Visual Studio 2010 using DEF

I inherited the multi-page solution of huge C ++ with many dynamic libraries, but without

__declspec(dllexport) 

I learned that it is not necessary to insert any dllexport (it will be a lot of work), but you can use the .def file instead as the corresponding DLL file.

To try that I built the โ€œHello World DLLโ€ project from here , removed dllexport from the header and ... lagged frantically. According to the page already quoted , my key question is how

 "[..] use the .def file when building the DLL." 

My .def file (I try to use the code using the Add method only):

 LIBRARY MathFuncsDll EXPORTS ?Add@MyMathFuncs @ MathFuncs@ @ SANNN@Z 

How to use it when creating a DLL in Visual Studio 2010 to export the Add method?

+7
source share
1 answer

After half a day before this problem, I found a solution: described here .

To resume the process of exporting characters with .def files to VS2010 using my own words:

  • Tell VS2010 to compile a dynamic library (DLL). This is done in the library project properties page .
  • Create a module definition file (.def) using mutilated (decorated) names (at least when your C ++ language). If you use dllexport, you can display the already exported characters of your .dll as described here . If you have not exported anything yet, see.
  • Add .def to the library definition on the property page .
  • Compile
  • Check the correctness of your work, for example, "Avoiding Dependencies" by opening a dependent file, for example ..Exe. You should see the just compiled library in the dependency tree under the dependent file. There should not be any errors or warnings, for example. no red color.

If you have further questions regarding the .def files, look at the final file , Module Definition File .

+11
source

All Articles