{"id":3847,"date":"2014-03-30T06:01:47","date_gmt":"2014-03-30T06:01:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/can-i-call-c-dll-in-c-program-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:01:47","modified_gmt":"2014-03-30T06:01:47","slug":"can-i-call-c-dll-in-c-program-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/can-i-call-c-dll-in-c-program-collection-of-common-programming-errors\/","title":{"rendered":"can i call C# dll in C++ program ?-Collection of common programming errors"},"content":{"rendered":"<p>Well if you are using a native C++ program then I want to question why you want to use things from System.Windows. Esentially System.Windows is a subset of what is exposed through the Win32 API. Whats more, if you want to use System.Windows then you should just create a managed application to start off with. It will be a lot less fiddly and the potential problems are not worth the effort that you would put into the interop work.Whats more, if you are using System.Windows from a native application then the constant\u00a0managed\/unmanaged transitions will make the application run a lot slower than if you made it purely native or managed.If you want a framework for GUI applications in a native application then look either at MFC or QT.<\/p>\n<p>If you are trying to get access to\u00a0a third party library written in a .net language though then you have an option which is actually a\u00a0lot neater than the above post. You can create a native wrapper class. If you create a DLL to host this wrapper so you don&#8217;t have to build your main project with \/clr then it will make things easier on you. You can then use gcroot to hold the managed class reference and things will go from there.<\/p>\n<p>@Lim Bio LiongBe careful with that, CLR hosting is a bit confusing but it probably doesn&#8217;t work as you think it does.The first thing to remember is the .Net framework version of the CLR will load into a pure native process the first time managed code is called even without an explicit hosting environment. Executables with a managed header actually load the CLR up right away to stop the hit of the CLR loading in at runtime. What CLR hosting actually is, is a way to control and get notifications from the CLR while it is running. So it gives you a chance to hook into it to get information or control behaviour, that is all.<\/p>\n<p>If you create a native application and a mixed mode dll and use LoadLibrary\/GetProcAddress to call a managed function from the DLL, you will notice that it will load the CLR in as soon as the managed code is executed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well if you are using a native C++ program then I want to question why you want to use things from System.Windows. Esentially System.Windows is a subset of what is exposed through the Win32 API. Whats more, if you want to use System.Windows then you should just create a managed application to start off with. [&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-3847","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3847","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=3847"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3847\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}