What is dllspec(dllimport) and dllspec(dllexport) means

后端 未结 3 1961
庸人自扰
庸人自扰 2021-02-06 18:48

After googling, i came to know that Dllimport makes the function available for other modules,

is it mandatory to declare function with extern \"c\" identifier?

A

3条回答
  •  难免孤独
    2021-02-06 19:33

    __declspec(dllexport) exports a symbol. It makes it available from outside a DLL.

    __declspec(dllimport) imports a symbol. It practically says "this symbol is not defined in this application, it needs to be imported from a DLL file".

    You don't have to declare it with extern "C". If you don't use extern "C", then the symbol will be exported as a C++ symbol, and you will only be able to call it from C++ (and languages that support calling C++ DLLs). If you use extern "C", then the symbol will be exported as a C symbol, and you will be able to call it from languages that support caling C DLLs.

    If you want to use your DLL in C#, you will need to use extern "C".

    Here is an excellent tutorial that shows you how to use a C++ DLL in C#: How to marshal a C++ class. I have used solution A in many projects at work.

    Also, here is a short tutorial on how you can use a C++ DLL in another C++ application: How to create and use DLL in C++.

提交回复
热议问题