{"id":4528,"date":"2014-03-30T13:12:55","date_gmt":"2014-03-30T13:12:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-create-some-class-from-dllconstructor-in-dll-collection-of-common-programming-errors\/"},"modified":"2014-03-30T13:12:55","modified_gmt":"2014-03-30T13:12:55","slug":"how-to-create-some-class-from-dllconstructor-in-dll-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-create-some-class-from-dllconstructor-in-dll-collection-of-common-programming-errors\/","title":{"rendered":"How to create some class from dll(constructor in dll)?(?++)-Collection of common programming errors"},"content":{"rendered":"<p>You need to declare your class using the <code>__declspec(dllexport)<\/code> keyword when building the DLL. When using the DLL, the class needs to be declared with <code>__declspec(dllimport)<\/code>:<\/p>\n<pre><code>#ifdef COMPILING_DLL\n#define DECLSPEC_CLASS __declspec(dllexport)\n#else\n#define DECLSPEC_CLASS __declspec(dllimport)\n#endif\n\nclass DECLSPEC_CLASS MyClass\n{\n...\n}\n<\/code><\/pre>\n<p>When the DLL is compiled, you should add -DCOMPILING_DLL to the list of defines.<\/p>\n<p>When using the class, you must statically link with the DLL, i.e. pass the import library mydll.lib to the main program.<\/p>\n<p>If you want to load the DLL <strong>at runtime<\/strong>, you need to have a C-function in the DLL which creates a object and returns it for you. There is no way to lookup a constructor dynamically in a DLL (using GetProcAddress()).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You need to declare your class using the __declspec(dllexport) keyword when building the DLL. When using the DLL, the class needs to be declared with __declspec(dllimport): #ifdef COMPILING_DLL #define DECLSPEC_CLASS __declspec(dllexport) #else #define DECLSPEC_CLASS __declspec(dllimport) #endif class DECLSPEC_CLASS MyClass { &#8230; } When the DLL is compiled, you should add -DCOMPILING_DLL to the list of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4528","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4528"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4528\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}