{"id":5161,"date":"2014-03-30T19:17:52","date_gmt":"2014-03-30T19:17:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/pointers-in-and-out-of-dlls-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:17:52","modified_gmt":"2014-03-30T19:17:52","slug":"pointers-in-and-out-of-dlls-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/pointers-in-and-out-of-dlls-collection-of-common-programming-errors\/","title":{"rendered":"Pointers in and out of DLLs-Collection of common programming errors"},"content":{"rendered":"<p>Yes.<\/p>\n<p>Assuming you are using Microsoft Visual Studio as your development environment you can export a class rather directly from a dll. Add a define to your dll project something like <code>BUILDING_THE_DLL<\/code> and the following code snippit will export a c++ class wholesale from the dll.<\/p>\n<pre><code>#ifdef BUILDING_THE_DLL\n#define DLLEXPORT __declspec(dllexport)\n#else\n#define DLLEXPORT __declspec(dllimport)\n#endif\n\nclass EXPORT DllClass\n{\n....\n};\n<\/code><\/pre>\n<p>This is a highly coupled solution and only works if you build the application and its dll using the same development environment, and rebuild both whenever the class definition changes in any way. this method is heavilly used by the MFC library.<\/p>\n<p>To achieve a greater independence between the dll and app, one typically defines a relatively immutable interface and uses that to make builds more independent, and possibly use different build environments.<\/p>\n<p>An implementation in your dll would look something like this:<\/p>\n<pre><code>struct IMyInterface {\n   virtual void Destroy() =0;\n   virtual void Method() = 0;\n};\n\nclass MoDllObject : public IMyInterface\n{\n\/\/ implementation\n};\n\nbool EXPORT DllGetInterface(IMyInterface** ppOut)\n{\n  *ppOut = new MyDllObject();\n   return true;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Yes. Assuming you are using Microsoft Visual Studio as your development environment you can export a class rather directly from a dll. Add a define to your dll project something like BUILDING_THE_DLL and the following code snippit will export a c++ class wholesale from the dll. #ifdef BUILDING_THE_DLL #define DLLEXPORT __declspec(dllexport) #else #define DLLEXPORT __declspec(dllimport) [&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-5161","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5161","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=5161"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5161\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}