Jump to content
Eltion

AutoIt .NET with C++/CLI Wrapper

Recommended Posts

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
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 by TheXman

Share this post


Link to post
Share on other sites
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

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 - Wiki
OutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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 - Wiki
OutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...