none
CommunicatorAPI - Unable to start conversation

    คำถาม

  • Hello All,

     

    I'm almost done writing an application to sign into LCS, send a message and then log off the system. I'm able to login and logoff, however whenever I attempt to start a conversation window it fails to do anything. I eventually added a else statement (shown at the very bottom of code) to see if the msgrAdv value was returning 'null', which it was.. This always returns 'null' and I followed samples provided by Microsoft but none work..

     

    Would someone please take a look at the below code and possibly provide some direction? Thanks!

     

     

    Code Block

    //load selected contacts into ArrayList.

    Array contactArray = new Array();

    contactArray.Add(xxxxxxx@ditsc.com);

     

    //dimension object array to the number of contacts selected

    object[] sipUris = new object[contactArray.Count];

    int currentObject = 0;

     

    //iterate over contactArray and load each individual

    //contact into object array element.

    foreach (object contactObject in contactArray)

    {

    sipUris[currentObject] = contactObject;

    currentObject ++;

    }

     

    long windowHandle;

     

    CommunicatorAPI.IMessengerAdvanced msgrAdv = communicator as CommunicatorAPI.IMessengerAdvanced;

     

    if (msgrAdv != null)

    {

    try

    {

    object obj = msgrAdv.StartConversation(

    CONVERSATION_TYPE.CONVERSATION_TYPE_IM,

    sipUris, // object array of signin names

    null,

    "Testing",

    "1",

    null);

    windowHandle = long.Parse(obj.ToString());

    }

    catch (COMException ex)

    {

    MessageBox.Show(ex.ErrorCode.ToString());

    };

    }

    else

    {

    MessageBox.Show("msgrAdv is null");

    }

     

     

    31 ตุลาคม 2550 17:02

ตอบทั้งหมด

  • Did you add the reference to the "Microsofot Office Communication 2007 Type Library" to your C# project?  You also need to create and initialize the instance of communicator before you call the code you posted.

     

    The following code sample from the help file assumes that Communicator is running but not logged in.  If yours is already logged in, then you can skip the call to communicator.Signin().  Or you might want to look at the AutoSignin() method instead. 

     

     

    Code Block

    CommunicatorAPI.MessengerClass communicator = new CommunicatorAPI.MessengerClass();
    bool connected = false;
    int parentHandle = 0;
    string account = "jaya@contoso.com";
    string'>mailto:jaya@contoso.com">jaya@contoso.com";
    string passwd = "abc123";
    try
    {
         communicator.Signin(parentHandle, account, passwd);
         connected = true;
    }
    catch (ArgumentException AE)
    {
        Console.WriteLine(AE.Message.ToString());
    }
    catch (COMException CE)
    {
       Console.WriteLine(CE.ErrorCode.ToString());
    }

     

     

    1 พฤศจิกายน 2550 16:00
  • Thanks Oscarnew!

     

     I didn't have the 2007 Type Library added, I did just add it and it still returns null. I copied the example from microsoft exactly which is why I can't figure out why the msgrAdv object is always null.. So I'm still stuck in the same please. But I have addded all the code relating to LCS below, hopefully that will help.

     

    Code Block

    // Communicator Classes

    CommunicatorAPI.MessengerClass communicator = new CommunicatorAPI.MessengerClass();

    CommunicatorPrivate.MessengerPrivClass communicatorPrivate = null;

    bool connected = false;

    int parentHandle = 0;

    // Messenger Events we want to monitor

    private DMessengerEvents_OnIMWindowContactAddedEventHandler AddContactToConversation;

    private DMessengerEvents_OnIMWindowCreatedEventHandler ConversationCreated;

    private DMessengerEvents_OnSigninEventHandler MessengerSignin;

    private DMessengerEvents_OnSignoutEventHandler MessengerSignout;

     

    .....

     

    private void DITSCMain_Load(object sender, EventArgs e)

    {

    if (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length > 1)

    {

    MessageBox.Show("You may not run multiple instances of the DITSC LCS Blaster!", "Multiple instances detected!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);

    Application.Exit();

    return;

    }

    else

    {

    PWaitWin.Visible = true;

    try

    {

    communicator.AutoSignin();

    SendKeys.Send("{ENTER}");

    SendKeys.Send("{ENTER}");

    connected = true;

    }

    catch (ArgumentException AE)

    {

    MessageBox.Show(AE.Message.ToString());

    }

    catch (COMException CE)

    {

    if (CE.ErrorCode.ToString().Equals("-2130705660") == false)

    {

    MessageBox.Show(CE.ErrorCode.ToString());

    }

    }

    populateListCombo();

    populateReipsDGrid(this.AccSendTo.Text);

    RegistryKey regKey = Registry.CurrentUser.CreateSubKey("Software\\DITSC LCS Blaster\\UsrSettings");

    string ShowWinOnStart = (string)regKey.GetValue("ShowBlasterOnStart");

    // IN PROGRESS

    if (ShowWinOnStart.Equals("True") == false)

    {

    this.Visible = false;

    uKnowShowWin.Visible = false;

    this.SendBlastCMOp.Text = "Show Blaster";

    DITSCnotifyIcon.ShowBalloonTip(500, "DITSC - LCS BlasterTool is now hidden!", "Right-click the uKnow icon to restore the window.", ToolTipIcon.None);

    }

    PWaitWin.Visible = false;

    }

    }

     

     

    private void button3_Click(object sender, EventArgs e)

    {

    //load selected contacts into ArrayList.

    /*Array contactArray = new Array();

    contactArray.Add(xxxxx@ditsc.com);

    //dimension object array to the number of contacts selected

    object[] sipUris = new object[contactArray.Count];*/

    object[] sipUris = { "user@company.com" };

    int currentObject = 0;

    //iterate over contactArray and load each individual

    //contact into object array element.

    /*foreach (object contactObject in contactArray)

    {

    sipUris[currentObject] = contactObject;

    currentObject ++;

    }*/

    long windowHandle;

    CommunicatorAPI.IMessengerAdvanced msgrAdv = communicator as CommunicatorAPI.IMessengerAdvanced;

    if (msgrAdv != null)

    {

    try

    {

    object obj = msgrAdv.StartConversation(

    CONVERSATION_TYPE.CONVERSATION_TYPE_IM,

    sipUris, // object array of signin names

    null,

    "Testing",

    "1",

    null);

    windowHandle = long.Parse(obj.ToString());

    }

    catch (COMException ex)

    {

    MessageBox.Show(ex.ErrorCode.ToString());

    };

    }

    else

    {

    MessageBox.Show("msgrAdv is null");

    }

    }

     

     

    1 พฤศจิกายน 2550 19:07
  • I am having the sample problem.  Can someone please let me know whether they were able to make this sample code worked?

     

    15 พฤศจิกายน 2550 19:17