c++ - Export POD-structure from DLL -
consider following source library.cpp
struct parameter { const char *path; int num; bool flag; /* , many, many more members... */ }; __declspec(dllexport) void func(const parameter &); this compiles library library.dll.
as far understand, export declarations export functions , data. since structure parameter doesn't define functions it's not necessary here , omitted it.
but
dumpbin.exe /exports library.dll reveals, there in fact real difference here: method operator = (const parameter &) exported.
question: there important reasons export parameter, i.e. add __declspec(dllexport) in front of parameter? best practice pod-structures.
normally, pod struct, contain data(that of fundamental types) , no functions, declared in ".h" file given along corresponding .dll.
//mydll.h ------------------------------------------------- #ifndef __mydll_dot_h__ #define __mydll_dot_h__ struct parameter { const char *path; int num; bool flag; }; #ifdef __dllexport__ __declspec(dllexport) void func(const parameter &); #else __declspec(dllimport) void func(const parameter &); #endif #endif //#ifndef __mydll_dot_h__ //mydll.h ------------------------------------------------- //client_of_mydll.cpp ------------------------------------- #include "mydll.h" int main() { parameter stparameters; //initialize parameters of stparameters func(stparameters); } //client_of_mydll.cpp ------------------------------------- edit: since pod contains purely data, declaration of such pod remains same in dll , client of dll. here purely data means no member functions if pod has struct say, b inside member function b::func(). so, there no important reasons export structure along function.
Comments
Post a Comment