+ 1

What for are the __declspec and __cdecl operators needed ???

24th Jun 2018, 6:35 AM
Pravin Yadav
Pravin Yadav - avatar
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();
24th Jun 2018, 8:56 AM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
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
24th Jun 2018, 7:40 AM
Max
Max - avatar
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
24th Jun 2018, 9:01 AM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar