{"id":318,"date":"2025-01-07T16:29:21","date_gmt":"2025-01-07T08:29:21","guid":{"rendered":"https:\/\/thihaoo.com\/?p=318"},"modified":"2025-01-07T16:30:24","modified_gmt":"2025-01-07T08:30:24","slug":"load-c-dll-from-c","status":"publish","type":"post","link":"https:\/\/thihaoo.com\/?p=318","title":{"rendered":"Load C# DLL from C++\u00a0\u00a0\u00a0"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This is to load C# DLL from C++ and call its functions&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"pch.h\" \n#include &lt;iostream> \n#include&lt;Windows.h> \n#include&lt;string> \n\nusing namespace std; \n\nint main() \n{    \n    typedef int(__cdecl* _add)(int a, int b); \n\n    HMODULE lib = LoadLibrary(L\"C:\\\\Users\\\\Thiha\\\\LIB\\\\bin\\\\x64\\\\Release\\\\ClassLibrary1.dll\"); \n\nif (lib == NULL) \n{ \n   std::cout &lt;&lt; \"Error loading DLL...\" &lt;&lt; std::endl; \n\n   return 1; \n} \n\n \/\/ Just testing Add function from C# DLL \n auto pAdd = (_add)GetProcAddress(lib, \"Add\");\n int c = pAdd(5, 7); \n\n \/\/ Calling printLabel_Sharp function from C# DLL \n  typedef void(__cdecl* _printLabel_Sharp)(); \n  auto printLabel = (_printLabel_Sharp)GetProcAddress(lib, \"printLabel_Sharp\"); \n\n  printLabel(); \n\n} <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is to load C# DLL from C++ and call its functions&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","WB4WB4WP_MODE":"","WB4WP_PAGE_SCRIPTS":"","WB4WP_PAGE_STYLES":"","WB4WP_PAGE_FONTS":"","WB4WP_PAGE_HEADER":"","WB4WP_PAGE_FOOTER":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-blog-english"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/thihaoo.com\/index.php?rest_route=\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thihaoo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thihaoo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thihaoo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thihaoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318"}],"version-history":[{"count":2,"href":"https:\/\/thihaoo.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/thihaoo.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions\/320"}],"wp:attachment":[{"href":"https:\/\/thihaoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thihaoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thihaoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}