Question about exporting / importing and exporting DLLs in Windows

Hi guys, I have some quick questions on windows dll.

I mainly use ifdefs to handle dllexport and dllimport, my question is about hosting dllexports and dllimports, as well as the extern keyword.

I put dllimports / dllexports in the header files, but do I need to put dllexport and dllimports on the actual definition?

What about typedefs?

Did I put dllimport / dllexport in front? how in

dllexport typedef map<string, int> st_map

Also regarding the extern keyword, I saw that it is used as follows:

extern "C" {

dllexport void func1();

}

I also saw that it is used as follows:

extern dllexport func1();

"", , , , ? , dllexport, dllimport, , ?

, , , typdefs, , , dll.

- , ?

EDIT:

, , , , , linux windows, :

mydll.h

#ifdef WINDOWS
#   ifdef PSTRUCT_EXPORT
#   define WINLIB __declspec(dllexport)
#   else
#   define WINLIB __declspec(dllimport)
#   endif
#else
#  define WINLIB
#endif

WINLIB void funct1();

:

mydll.cpp

#define PSTRUCT_EXPORT

void funct1() <---- do i need to add WINLIB in front of it? 
                      Or is doing it in the header enough?
+5
2

-, typedef. , , . / .

, , , makefile , - :

#if defined( LIBRARY_CODE )
#define MYAPI __declspec(dllexport)
#else
#define MYAPI __declspec(dllimport)
#endif

extern MYAPI void func1();
class MYAPI MyClass {
    ...
};

C ++, :

#if defined( __cplusplus__ ) // always defined by C++ compilers, never by C
#define _croutine "C"
#else
#define _croutine
#endif

extern _croutine void function_with_c_linkage();

, ++ ( ), , C.

+7
  • typedefs dllimport/dllexport,
  • dllimport/dllexport , /
  • (cdecl, stdcall,...), , ( Visual Basic use stdcall)
  • extern "C", ++, #ifdef __cplusplus, ++.

OpenSource. , . ++ extern "C".

+2

All Articles