Jump to content

AutoIt .NET with C++/CLI Wrapper


Eltion
 Share

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);

 

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

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Is your testdll.dll a 32-bit or 64-bit DLL?

In AutoIt, are you running your script as 32-bit or 64-bit?

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...