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 :
Finance | Project Operations, Human Resources, ...
Answered

How to code DLL events in dynamics ax 2012 r3 ?

(1) ShareShare
ReportReport
Posted on by 14
Hello,
we work with Microsoft Dynamics Ax 212 R3 (CU12) and we need to access to the DLL events for our telephony system. 
The file is in the client bin folder and is imported in the references.
I don't know how to call these events in x++ (in c# examples we can see delegate methods).
All basics properties are ok, we can make a call, we can transfer a call too but we cannot implement the alerting call, the agent status, the incoming call  ...
We can't use managed_host principles because no control is return by the DLL.
All my research and my tests are ko.
Can anyone help us ?
Thanks in advance.
 
Stéphane A.
I have the same question (0)
  • Martin Dráb Profile Picture
    237,758 Most Valuable Professional on at
    You mentioned you wanted to call those events from X++, but I think you mean subscribing to those events, i.e. registering your X++ methods as handlers of the events. Is it so?
     
    I don't remember if it's possible in AX 2012, but if so, you should utilize += eventhandler(...). If it's not possible, you should handle events in .NET code and call AX methods from there.
  • SA-05060738-0 Profile Picture
    14 on at
    Hello Martin,
    yes that's it. Sorry for my poor English. 
    I don't know how to subscribe to these events.
    I read full of posts you made on it but didn't find any answer i can use.
    If i didn't make mistake in my code, i tried += eventhandler() with no success because i don't understand how to get the link between the dll and x++ for the events.
    I'm going to try to explain what i mean :
     
    c# is coded like this :
     
    ctiObj = new CtiServerConnector.Control();
    ctiObj.CstaAlertingEvent += new CtiServerConnector.Events.CstaAlerting(ctiObj_CstaAlerting_Event);
     
    With :
            public delegate void CstaAlerting(string agentNum, string refCom, string caller, string called, string clientCode, string callerStr, string calledStr);
     
            void ctiObj_CstaAlerting_Event(string agentNum, string refCom, string caller, string called, string clientCode, string callerStr, string calledStr)
            {
                refComAlerting = refCom;
                myDebug("\r\nCstaAlerting : Agent=" + agentNum + " ref=" + refCom +
                                 " caller : " + caller + " called : " + called + " clientCode : " + clientCode +
                                 " callerStr : " + callerStr + " calledStr : " + calledStr);
            }
     
    I don't know how to get the same thing in x++ because of the CtiServerConnector.Events which has no accessible code.
    Maybe have you an idea ? 
     
    Thanks a lot for your help
  • Martin Dráb Profile Picture
    237,758 Most Valuable Professional on at
    Maybe you should first learn how to subscribe X++ methods to X++ delegates before complicating it by involving .NET Interop.
     
    You'll see that you need to create a method with the same signature as the delegate and use +=eventhandler() to register the handler. For example:
    // Static handler
    objectA.myDelegate += eventhandler(MyClass::staticHandler);
    // Instance handleer
    objectA.myDelegate += eventhandler(myObject.instanceHandler);
    When you're comfortable with that, try subscribing to the managed event:
     
    ctiObj = new CtiServerConnector.Control();
    ctiObj.CstaAlertingEvent += eventhandler(myObject.ctiObj_CstaAlerting_Event);
  • SA-05060738-0 Profile Picture
    14 on at
    I already have created the delegate method and the static handler like this :
     
    In a class named Bij_CTI2024
    delegate void CstaAlertingEventDelegate(str agentNum, str refCom, str caller, str called, str clientCode, str callerStr, str calledStr)
    {
    }
     
    public static void on_CstaAlertingEvent(str agentNum, str refCom, str caller, str called, str clientCode, str callerStr, str calledStr)
    {
        info(strFmt("\r\nCstaAlerting : Agent=%1 ref=%2 caller : %3 called : %4 clientCode : %5 callerStr : %6 calledStr : %7",
                    agentNum,
                    refCom,
                    caller,
                    called,
                    clientCode,
                    callerStr,
                    calledStr));
    }
     
    In a form method Init :
    Bij_CTI2024 cti2024 = new Bij_CTI2024();
    cti2024.CstaAlertingEventDelegate += eventhandler(Bij_CTI2024::on_CstaAlertingEvent);
     
    Am i right ?
     
  • Martin Dráb Profile Picture
    237,758 Most Valuable Professional on at
    Test it (by invoking the delegate) to see if it works or not. It looks good to me, but testing is testing...
  • SA-05060738-0 Profile Picture
    14 on at
    You're right :) i will ...
     
    Best regards
  • SA-05060738-0 Profile Picture
    14 on at
    Hello Martin,
    I finally found the time to test the code below.
    It works well alone.
    Now I face to my first problem : .NET interop
    i don't know how to subscribe to the DLL events
     
    ctiobj doesn't have any intellisense on events but only on properties
     
    it's like i have no access to the managed event
     
    I really don't understand how i can do that
     
     
  • Martin Dráb Profile Picture
    237,758 Most Valuable Professional on at
    Don't depend on IntelliSense; write the code and try compiling it. Unfortunately, I don't remember whether it worked in AX 2012. It's quite possible that it isn't supported, but maybe you're lucky.
  • SA-05060738-0 Profile Picture
    14 on at
    Well ... i'm not 😢
    i get this error  : "Parentheses are required on a method call"
    cti.CstaAlertingEvent += eventhandler(Bij_CTI2024::on_CstaAlertingEvent);
     
    I tried a new approach with cti.add_CstaAlertingEvent(ManagedEventHandler val).
     
    First, i deleted the "static" property in my class and then i wrote this in my form:
     
    public void Init()
    {
        CtiServerConnector.Control cti;
       
        super();
        // Init contrôle CTI
        cti = new CtiServerConnector.Control();
       
        // Event cti
        cti.add_CstaAlertingEvent(new ManagedEventHandler(this,'on_CstaAlertingEvent')); // With on_CstaAlertingEvent as new method in the form
    }
     
    this code is compiling right
    but in execution Dynamics crashes !
     
    In my research, i saw ManagedEventHandler seems to need "Managed_Host" control.
    "Managed_Host" control needs formcontrol type in the DLL Reference (like AxReportViewer in the Microsoft.Dynamics.Ax.Frameworks.Controls)
    But what can we do if the Reference has no control ????
     
    I think Dynamics 2012 is not compatible with this DLL.
    The only way i see is an ocx ...
     
    Do you think i am right ?
  • Verified answer
    Martin Dráb Profile Picture
    237,758 Most Valuable Professional on at
    I think it compiles just because the compiler doesn't check types there. The code doesn't make sense to me and you indeed found and it can't work.
     
    Maybe it's time to consider again the suggestion at the end of my first reply.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 704 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 570 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 408 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans