+ 1
What for are the __declspec and __cdecl operators needed ???
3 ответов
+ 1
Note: The following summary has been extracted from MSDN documentation.
__declspec is a Microsoft specific extension to the C++ language. The __declspec(modifier-seq) refers to the extended attribute syntax (modifier-seq) for specifying storage-class information.
~Usage~
1. Importing data/function call from dll using __declspec(dllimport)
In the case of data/function, using __declspec(dllimport) is a convenience item that removes a layer of indirection. In other word, making it possible to import dll's implementation to client code with less complexity.
~Example~
#include "MyDll.h"
__declspec(dllimport) void myFunction();
// Calling myFunction somewhere inside MyDll.h
myFunction();
2. Exporting class/class members/data/function using __declspec(dllexport)
This keyword enables linker to make an object accessable to other dlls and also elimimates the need for .def file*. This convenience is more apparent when trying to export decorated C++ function names**.
~example~
void __declspec(dllexport) f();
0
__cdecl is a calling convention for c/c++ programs https://en.m.wikipedia.org/wiki/X86_calling_conventions
__declspec is for custom microsoft extensions to c++ and does various things like prologe/epilog supression, creating threadlocal variables.... see here for some examples https://stackoverflow.com/questions/2284610/what-is-declspec-and-when-do-i-need-to-use-it
the last is custom to the mircosoft c++ compiler. i think __cdecl is too, but many compilers have a similar method of declaring the calling convention
0
_____
* Is a text file containing one or more module statements that describe various attributes of a dll.
** A decorated name is an encoded string created by the compiler during compilation of an object, data, or function definition.
External resource:
https://msdn.microsoft.com/en-us/library/dabb5z75.aspx