We have MBS Axapta 3 in our company. The boss doesn't want to migrate to a later version of Dynamics AX, so I'm stuck with this.
Basically what I'm trying is to access my own COM DLL from Axapta's X++ code. I would like to be able to access .net functions, so I've created my DLL using this tutorial:
http://www.softwareandfinance.com/CSharp/CS_ClassLib_Step1_CreateProject.html
The final code of my DLL is:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ClaseCOM
{
public class Test
{
[Guid("12D1EDAC-20C0-4faa-A774-B6F4C300B47E")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IMathCtrl
{
[DispId(1)]
int AddNumbers(int a, int b);
}
[Guid("282902B4-5FB9-461d-9CD0-FE8DD851F979")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("SFTCSServer.MathCtrl")]
public class MathCtrl : IMathCtrl
{
public MathCtrl() { }
public int AddNumbers(int a, int b)
{
return (a + b);
}
public int MuliplyNumbers(int a, int b)
{
return (a * b);
}
}
public static string ReturnString(string a)
{
return "Ha enviado " + a;
}
}
}
After I generate the tbl, and register the dll with gacutil, I can call my dll from Axapta, but it doesn't recognize any method. It gives an error "method does not exist"
This is my x++ code:
static void DT_PruebasCOM(Args _args)
{
COM PruebaCOM;
COMVariant a,b; ;
PruebaCOM = new COM('ClaseCOM.Test');
// create variants to hold the arguments for the functions
a = new COMVariant(COMVariantInOut::OUT, COMVariantType::VT_I4);
b = new COMVariant(COMVariantInOut::OUT, COMVariantType::VT_I4);
PruebaCOM.ReturnString();
}
It gives the same error for AddNumbers and MathCtrl and IMathCtrl, so I don't really know if I need to setup something in order to make this methods visible in for the Axapta code.
Any ideas on how can I solve this?
Thanks!!