Eltion 0 Posted November 23, 2020 Hi, I have a managed class dll from c#. Using this guide here https://www.codeproject.com/articles/556582/usingplusc-plusfromplusnativeplusc-b-bpluswith I was able to create a wrapper around my managed library with C++/CLI. Then created a unmanaged c++ library using that. I've tested it in a console application and everything works fine, but when I try to access the unmanaged c++ library using DllCall it does not work. #C sharp public class MathTest { public int add(int x, int y) { return x + y; } } #Wrapper #include "pch.h" #using "TEST3.dll" #include <msclr\auto_gcroot.h> #include "Wrapper.h" using namespace System::Runtime::InteropServices; class MathTestWrapperPrivate { public: msclr::auto_gcroot<MathTest^> MathTest; }; MathTestWrapper::MathTestWrapper() { _private = new MathTestWrapperPrivate(); _private->MathTest = gcnew MathTest(); } int MathTestWrapper::add(int a, int b) { return _private->MathTest->add(a, b); } #Unmanaged dll #include "pch.h" #include "testdll.h" #include "Wrapper.h" int add(int a, int b) { MathTestWrapper w; return w.add(a, b); } #testdll.h #pragma once #ifdef TESTDLL_EXPORTS #define TESTDLL __declspec(dllexport) #else #define TESTDLL __declspec(dllimport) #endif extern "C" TESTDLL int add(int a, int b); Share this post Link to post Share on other sites
TheXman 405 Posted November 24, 2020 (edited) 3 hours ago, Eltion said: when I try to access the unmanaged c++ library using DllCall it does not work. Where is your AutoIt script with the DllCall that "does not work"? Edited November 24, 2020 by TheXman About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
boom221 2 Posted November 24, 2020 Did you forget to add the ":cdecl" after the return type? Share this post Link to post Share on other sites
Eltion 0 Posted November 24, 2020 7 hours ago, TheXman said: Where is your AutoIt script with the DllCall that "does not work"? $a = DllOpen("testdll.dll") $c = DllCall($a, "int:cdecl", "add","int",5,"int",5) MsgBox(0,"",@error) It never goes to the MsgBox so I don't see the @error at all Share this post Link to post Share on other sites
water 2,391 Posted November 24, 2020 I suggest to check the returncode of DllOpen as well. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
Eltion 0 Posted November 24, 2020 6 minutes ago, water said: I suggest to check the returncode of DllOpen as well. DllOpen returns 1. Share this post Link to post Share on other sites
water 2,391 Posted November 24, 2020 Looks good. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
TheXman 405 Posted November 24, 2020 Is your testdll.dll a 32-bit or 64-bit DLL? In AutoIt, are you running your script as 32-bit or 64-bit? About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites