Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MiTai SDK with .net 4

Status
Not open for further replies.

septopus

Programmer
Jun 18, 2009
4
0
0
US
Hello all, maybe somebody here can help me? I'm a .net programmer (mostly vb.net) and my company has purchased the MiTel SDKs, it appears that they only come with cpp native code dlls so.. Can anybody assist me with either platform invoke signatures or other code/info on how to use these within managed code(pref. vb.net but c# would be fine too..) Where to find the signatures/how to generate them/etc.. Or if there's an easier way to go about this?.. I'm starting to learn cpp but it'll be a while before I'm proficient enough to use cpp directly.
 
Hi steeviet,

Thanks for your reply.

I've tried using the code you provided, and making a number of changes, like using bytes instead of chars, and changing the charsrt of the struct, but so far I've only been able to get a variety of random characters back (e.g. networkNumber = ?I). Is there something I'm missing?

Thanks again for your help.

Tyan
 
Do anybody know how I can call SXOpenPBX in C#?
I will apreciate you if you help me
 
I need to get call information from 3300 Mitel.
Does anybody know what are the its steps?
 
Hi
Thank you for your guide.
I think I couldn't ask my question clear.
I need some information about SXOpenPBX function.

I will appreciate you if you help me and let me know how I can call SxOpenPBX function by C#?
I called it:

[DllImport @"E:\Project\MitelSample\MitelSample\bin\MitaiClient80.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl, EntryPoint = "#1")]
public static extern int SXOpenPBX(__arglist);

private void button1_Click(object sender, EventArgs e)
{
int result, result2 = 0;
if (InitializServer())
{
result = SXOpenPBX(__arglist(false, "192.168.1.1", "8000", "", "40"));
....
}
}
but I got result=1404 and it mean is false. Are parameters wrong? Is my EntryPoint in DllImport attribute wrong? Which part of my code has problem that I can not get true result? Also, I don't have 2 NIC cards. but I don't know what it's problem.

Any help anyone could give this would be greatly appreciated.
 
I think slapin is trying to guide you towards the MiTAI developer guide. It will be impossible you you to develop anything with MitaiClient80.dll unless you have this documentation. Have you signed up with Mitel to get the developer kit?

From a quick look at your code I can see you doing two things wrong, firstly you are correct, the EntryPoint is wrong, if you have Visual Studio you can run the following which will list the functions and their entry points. (under the ordinal column)

Code:
dumpbin.exe -exports E:\Project\MitelSample\MitelSample\bin\MitaiClient80.dll

The second error I can see is the common mistake detailed on page 13 of the MiTAI Developers Guide, i.e. you need to terminate the function call with NULL or 0. To start with the line should be changed to:

Code:
SXOpenPBX(__arglist(false, "192.168.1.1", "8000", "", "40", 0));

The results i.e. 1404 are defined in errors.h which is provided with the API.

 
Hi Steev
Thank you for your replay
I ran dumpbin.exe and exported MitaiClient80.dll but its result was not clear. I attached its image. I can not found the functions as you can see the image.
What should I do?
Entrypoint in SXInit was 1 but I don't know what it is for SXOpenPBX function.
 
 http://tinyimage.net/image-F605_4C6236ED.jpg
Finally I could dump the dll. I found EntryPoint of SXOpenPBX is 10. But I have a new problem that is when I want to connect to the server it gives me 1360 error and can not tonnect to server.
Can you help me?
 
Finally I could dump the dll. I found EntryPoint of SXOpenPBX is 10. But I have a new problem that is when I want to connect to the server it gives me 1360 error and can not tonnect to server.
Can you help me?

16:39:03.578, 08/11/2010 (pid 2484): Starting main thread. Thread Id: 3788
16:39:03.578, 08/11/2010 (pid 2484): SXInit: Initialize Mitai Lid DONE.
16:39:03.578, 08/11/2010 (pid 2484): Entering SXOpenPBX.
16:39:05.828, 08/11/2010 (pid 2484): host MiTAI unknown
16:39:05.828, 08/11/2010 (pid 2484): Creation of MiSocketTCP failed, fatal !
16:39:05.890, 08/11/2010 (pid 2484): SSL handshake in mi_socket_open failed for PBX pbx_B
16:39:05.890, 08/11/2010 (pid 2484): ssumtai_disconnect - Cannot find Pbx Object Error.
16:39:05.890, 08/11/2010 (pid 2484): Aborting SXOpenPBX -- could not attach to pbx (null)
 
and this is the code

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MitelWrapper
{
    public static class CgtMitel 
    {
        public static int Init(string LogDirectory)
        {
            return MitaiClient80.SXInit( __arglist(
                            Constants.SX_STANDARD_CMD_RESPONSE_EVENT,
                            Constants.SX_LOG_DIR,
                            LogDirectory,
                            0 )
                            );
        }
        public static int OpenPBX(ref System.IntPtr hPbxObject, string PBX_IpAddress, string Network_IpAddress, int KeepAliveInterval)
        {
            int result = MitaiClient80.SXOpenPBX(__arglist
                                  (
                                      Constants.SX_PBX_HANDLE_PTR,
                                      ref hPbxObject,
                                      Constants.SX_PBX_IPADDRESS,
                                      PBX_IpAddress.ToCharArray(),
                                      Constants.SX_ADAPTER_IPADDRESS,
                                      Network_IpAddress,
                                      Constants.SX_COMPACT_MESSAGING,
                                      Constants.SX_KEEPALIVE_INTERVAL,
                                      KeepAliveInterval,
                                      null
                                  )
                              );

            return result;
        }

        public static int MonitorDN(ref System.IntPtr hMonitorobjp, System.IntPtr hPbxObject, string Dn)
        {
            int result = MitaiClient80.SXMonitor(__arglist
                                                    (
                                                    ref hMonitorobjp,
                                                    Constants.SX_PBX_HANDLE, hPbxObject,
                                                    Constants.SX_DN, Dn.ToCharArray(),
                //Constants.SX_CMD_RESPONSE_PROC,
                //new MyCallback(MonitorCallback),
                                                    null
                                                    )
                                                    );
            return result;
        }

        public static int StopMonitorDN(System.IntPtr hMonitorobjp)
        {
            int result =MitaiClient80.SXStopMonitor(__arglist
                                                     (hMonitorobjp, null)
                                                    );
            return result;
        }

        public static int MakeCall(System.IntPtr hMonitorobjp, string Source_Dn, string Dn)
        {
            int result = MitaiClient80.SXMakeCall(__arglist
                                                   (
                                                       Constants.SX_MONITOR_HANDLE,
                                                       hMonitorobjp,
                                                       Constants.SX_SOURCE_DN,
                                                       Source_Dn,
                                                       Constants.SX_DN,
                                                       Dn,
                                                       null
                                                   )
                                                );
            return result;
        }



        public static int  ClosePBX (System.IntPtr hPbxObject)
        {
            int result = MitaiClient80.SXClosePBX(__arglist
                                                    (
                                                        Constants.SX_PBX_HANDLE,
                                                        hPbxObject,
                                                        Constants.SX_EXIT,
                                                        null
                                                    )
                                                 );
            return result;
        }

        public static int  Shutdown()
        {
            return  MitaiClient80.SXShutdown();
        }
    }
}


 
You also need to Set and Activate callbacks

SXSetCallback
SXActivateCallbacks

Also you can stop monitoring some events by clearing calbacks

SXClearCallback
 
Hi
How can I set hmonitor_objp parameter in SXMonitor function in C#?
 
Hi,
I need to know what hPbxObject and hMonitorobjp are? and how and what should I set to them?
I will appreciate you if you give me a C# sample code.
I have Mitel Developer kit but I couldn't understand it.

Any help anyone could give this would be greatly appreciated.

Thanks,

Majid
 
Once again. It is not recommended to use this DLL directly. Make a wrapper, this way you will have your own set of C# classes.
 
They are both integers that are provided by calls to the API.

hPbxObject is returned by SXOpenPBX
hMonitorobjp is returned by SXMonitor

The example given above by gregoril already shows this. Where the "ref" keyword is used a reference to the variable is passed to the function. This allows the external DLL to set the value for the variable. After the function has been called it's value would have changed.

Incidentally gregoril, I used a uint for the mitel objects. as far as the c# code is concerned it's just a handle, not a valid memory pointer.


 
Hi Steev and Slapin
Thank you for your guide.
When I want to monitor I have to call SXMonitor() and then I have to call SXSetCallback() and SXActivateCallbacks
(), is it correct?

May I ask about SX_CALLBACK_PROC attribute in SXSetCallback function?
I know it is Mandatory attribute but I don't know how and what is it's variable? If I think correctlly, when I call SXSetCallback() with SX_CALLBACK_PROC attribute, the function return back events which were hapend durring of monitoring.
I called the SXSetCallback() like that:

public static int SetCallback(System.IntPtr g_hMonitor, System.IntPtr CallbackEventFromPBX)
{
int result = MitaiClient80.SXSetCallback(__arglist (
Constants.SX_MONITOR_HANDLE, g_hMonitor,
Constants.SX_CALLBACK_PROC, CallbackEventFromPBX,
null
) );
return result;
}
(I found it in the SDK sample.)
is the code correct?
what is g_hMonitor? can I declare it befor calling function with zero?
what is CallbackEventFromPBX and how can I set variable to it? from where?

 
Search google for "Callback function", when you understand the concept, search this thread for the word callback.

I feel I'm just repeating what is already in this thread, or just teaching you basic programming techniques. You are going to have to do some of this yourself.

 
Hi Steev
So sorry If I disturb you
I know that I ask so much but it's fact that I have a project about Mitel 3300 CXI. I'm not new but I really confused. I don't have time because I have to finish my program end of the current month. If you let me know CallbackEventFromPBX I will appreciate you.
 
Hi All
May I know how I can get the call backes after connecting to server and call SXMonitor() function?
I used this code:

int result = 0;
if (InitializServer())
{
if (GeneratePbx())
{
result = CgtMitel.MonitorDN(ref hMonitorobjp, hPbxObject1, "12");
}
}


The hMonitorobjp return a number and result is zero.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top