Skip to main content

Notifications

Announcements

No record found.

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.
  • SA-05060738-0 Profile Picture
    SA-05060738-0 14 on at
    How to code DLL events in dynamics ax 2012 r3 ?
    I'm scared about this solution but you're right.
     
    Thanks a lot Martin.
     
    Best regards.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,466 Most Valuable Professional on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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.
  • SA-05060738-0 Profile Picture
    SA-05060738-0 14 on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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 ?
  • Martin Dráb Profile Picture
    Martin Dráb 230,466 Most Valuable Professional on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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
    SA-05060738-0 14 on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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
     
     
  • SA-05060738-0 Profile Picture
    SA-05060738-0 14 on at
    How to code DLL events in dynamics ax 2012 r3 ?
    You're right :) i will ...
     
    Best regards
  • Martin Dráb Profile Picture
    Martin Dráb 230,466 Most Valuable Professional on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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
    SA-05060738-0 14 on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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
    Martin Dráb 230,466 Most Valuable Professional on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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
    SA-05060738-0 14 on at
    How to code DLL events in dynamics ax 2012 r3 ?
    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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans