How to create a DLL from existing C ++ code using a DEF file in Visual Studio 2010

I have inherited a C ++ project, and I need to convert it to a DLL in order to use it in other projects.

The code is enclosed in a Visual Studio 2010 solution. I can compile it and generate a DLL file, but there is no associated lib file. I am not a Windows developer, but it seems to me that I need to export the functions that I want to use, and there are two ways:

The first option would be to manually add __declspec (ddlexport) before each class or function that I want to export. Since there are many classes, and I do not have control over all the applications that will be associated with the library, the second option (DEF files) looks more promising.

Is there a way to generate a DEF file from an existing DLL file? I tried different solutions:

  • Using expdef . This is just a glitch without information.
  • Using dumpbin . I do not see function names. Just this:

    File Type: DLL

    Summary

        1000 .data
        2000 .idata
       18000 .rdata
        5000 .reloc
        1000 .rsrc
       98000 .text
       48000 .textbss
    

Nothing more. I think this means that I am not exporting anything. But this is exactly what I am trying to do. How to do it?

+4
source share
2 answers

Having encountered this problem several times over the course of several years, I found a solution today. This is a bit hacky, but actually it might be the best way with Visual Studio.

( , DLL ), , ( , , ), DEF - .

:

  • (EXE)
  • (DLL)
  • .DEF , , , .DEF, .DLL .LIB.
  • . DEF .
  • LIB

!

, ... Linker errors

"" , :

Linker error text

script "" , DEF. !

, ( , ). , , , , , , .

(NB: DLL- EXE)

+1

. - . , implib ( .lib), DLL. , , DLL, API ( C , Microsoft, ), . , , .def . MSDN, , , :

LIBRARY MyDLLName
EXPORTS
    function1
    function2
    ....

. "C", ++, WINAPI 32- . "", :

LIBRARY MyDLLName
EXPORTS
    exportedName1=internalFunctionName1
    exportedName2=internalfunctionName2
    ....

. .

+2

Source: https://habr.com/ru/post/1524291/


All Articles