Question on DLL Exporting/Importing and Extern on Windows

前端 未结 2 1668
情歌与酒
情歌与酒 2021-01-18 14:57

I have some quick questions on windows dll.

Basically I am using the ifdefs to handle the dllexport and dllimport, my question is actually regarding the placement of

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 15:52

    1. typedefs do NOT need a dllimport/dllexport, it's just a definition
    2. dllimport/dllexport are not standard, think of defining a macro for other platforms/compilers
    3. also take care of the calling convention (cdecl,stdcall,...) used otherwise you'll run into problems (if you need to be interoperable with Visual basic use stdcall)
    4. enclose within extern "C" so that your lib can be used from within C++ programs, use #ifdef __cplusplus to keep it only visible to C++.

    Have a look at different OpenSource libs. There you'll find plenty of examples on how making a good library header. There could be issues with name decoration in the case of C++ without the extern "C".

提交回复
热议问题