Hello,
I would like to know what the following declarations do. I have seen them in a C code on MSVisual Studio Compiled code.
extern "C" __declspec(dllexport)
extern "C" __declspec(dllimport)
I know somewhat that they are used to declare external linkage for functions(functional defined in different source file.But would like to know in detail how this works.
-Ajit
-
dllexport tells the compiler to generate a .lib file. dllimport tells the compiler to look in a .lib file for the function declaration (its definition will be in a dll).
-
It means the functions/classes that follow it are visible and accessible across a DLL boundary so you can link against them and call them from other code
-
The
extern "C"part tells a C++ compiler that the item being declared should use C linkage, which means that the name will not be mangled (or will be mangled in the same way that a C compiler would). This makes it so the item can be linked to from C code and most other languages as well, since C linkage is typically the standard used for that on a platform.The
__declspec(dllexport)and__declspec(dllimport)items are non-standard attributes that tell the compiler that the item should be exported (or imported) from a DLL. The__declspec()attribute is supported on MS compilers and probably other compilers that target Windows. I'm not sure if GCC does or not. Other storage class attributes that can be specified with__declspec()(at least in MSVC) includeuuid(),naked,deprecatedand others that provide the compiler with information on how an object or function should be compiled.
0 comments:
Post a Comment