web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

pass string to c++ .net dll

(0) ShareShare
ReportReport
Posted on by 40

Hi all!

I have got a little Problem and I hope someone of you knows how to solve it.
I wrote an own c++ .net dll (VS CLR Project) and use it through the reference option in Axapta.
Well so far no problem.

When i try to pass a string from Axapta to the dll it does not work and I have no more idea how to pass a string to this dll.
Here a bit source code so you can imagine what i did.

MyDLL.h:

#pragma once
using
namespace System;
namespace MyDLL {
   
public ref class SumClass
    {
   
public:
       
// constructor
       
static SumClass();
       
// returns a + b
       
double AddNumbers(double a, double b);
       
void stringTest(char* input);
   
};
}

MyDLL.cpp:

#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <atlimage.h>
#include "ximage.h"
#include "MyDLL.h"

using namespace std;

namespace MyDLL
{
    static SumClass::SumClass()
    {
    }
    double SumClass::AddNumbers(double a, double b)
   
{
       
return a + b;
   
}
    void SumClass::stringTest(char* input)
    {
    }
}

The AddNumbers function works fine within Axapta, but in my stringTest function he always says that "The class  does not contain this function".
So here the code how i use the DLL in Axapta:

    real a = 5;
    real b = 10;
    real result;
    str inputString;
    MyDLL.SumClass myDLL = new MyDLL.SumClass();

    ;
    result = myDLL.AddNumbers(a, b);

    // this does not work probably because of char* on dll side
    // but how to solve?!
    myDLL.stringTest(result);
   
    info(strfmt("Ergebnis: %1", result));

The first function "AddNumbers" works fine and without any problems. But how can i pass my string to the "stringTest" function?
Does anyone of you has an idea?

Thanks in advance!
Kind regards, Steven

*This post is locked for comments

I have the same question (0)
  • akuehn Profile Picture
    1,995 on at

    Hi Steven,

    i am not sure that pointers between AX and .NET are supported.
    Please try to use System.String insted of char*.

    And inside of AX you are using

    real result;
    ;
    myDLL.stringTest(result);
    info(strfmt("Ergebnis: %1", result));

    I am also not sure, that an real is passted to an char* correctly....

  • blablubb Profile Picture
    40 on at

     Hi akuehn,

     thank you for your answer. I don't know eighter if it is possible to exchange pointers.

    It is defenetly possible if you write a normal DLL not a .net DLL, the whole WinAPI class always does this. But i wasn't able to establish a connection between a normal C++ DLL and AX, so I took the .net DLL.

    But with System.String the DLL misses the function which uses these parameters, I really don't know why.
    If the arguments on both sides are not corresponding he does not compile the code and you can't execute your job.

    Is it really so hard to pass a simple string to an .NET DLL from AX? :o(

  • akuehn Profile Picture
    1,995 on at

    Normaly it should very simple to pass a string to .NET. I had nerver seen any problems.

    Did you have seen this documentation about marshaling/passing typs betwen AX and .net?

    http://msdn.microsoft.com/en-us/library/bb986175(AX.10).aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans