Eltion Posted November 23, 2020 Share 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); Link to comment Share on other sites More sharing options...
TheXman Posted November 24, 2020 Share 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 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
boom221 Posted November 24, 2020 Share Posted November 24, 2020 Did you forget to add the ":cdecl" after the return type? Link to comment Share on other sites More sharing options...
Eltion Posted November 24, 2020 Author Share 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 Link to comment Share on other sites More sharing options...
water Posted November 24, 2020 Share Posted November 24, 2020 I suggest to check the returncode of DllOpen as well. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Eltion Posted November 24, 2020 Author Share Posted November 24, 2020 6 minutes ago, water said: I suggest to check the returncode of DllOpen as well. DllOpen returns 1. Link to comment Share on other sites More sharing options...
water Posted November 24, 2020 Share Posted November 24, 2020 Looks good. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
TheXman Posted November 24, 2020 Share 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? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now