Establishing a POOM Session

Send Feedback

Before you can create and manipulate PIM items, you must first create an instance of the Outlook Mobile application object and then use it to establish a POOM session, which opens a connection to the PIM database.

To establish an POOM session

  1. Declare and initialize a pointer to the IPOutlookApp interface object:

    IPOutlookApp * g_polApp = NULL;
    
  2. Initialize COM:

    CoInitializeEx( NULL, 0);
    
  3. Create an Application class COM server object:

    CoCreateInstance(CLSID_Application, 
                     NULL, CLSCTX_INPROC_SERVER, 
                     IID_IUnknown, 
                     (void **)&g_pUnknown);
    
  4. Get a reference to the Outlook Mobile application interface object:

    g_pUnknown->QueryInterface(IID_IPOutlookApp, (void**)&g_polApp);
    
  5. Logon to the Outlook Mobile COM server:

    g_polApp->Logon(NULL);
    

Code Example

The following code example demonstrates how to create the Outlook Mobile application object and then use it to establish a POOM session.

Note   To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

IPOutlookApp * g_polApp = NULL;
IUnknown * g_pUnknown = NULL;

BOOL InitPoom(void) {
    BOOL bSuccess = FALSE;

    hr = CoInitializeEx( NULL, 0);
    if (hr != S_OK) {
        // CoInitializeEx failed.
        MessageBox(NULL, 
                   _T("CoInitializeEx failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = CoCreateInstance(CLSID_Application, 
                          NULL, CLSCTX_INPROC_SERVER, 
                          IID_IUnknown, 
                          (void **)&g_pUnknown);
    if (hr != S_OK) {
        // CoCreateInstance failed.
        MessageBox(NULL, _
                   _T("CoCreateInstance failed."), 
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = g_pUnknown->QueryInterface(IID_IPOutlookApp, (void**)&g_polApp); 
    if (hr != S_OK) {
        // QueryInterface failed.
        MessageBox(NULL, 
                   _T("QueryInterface failed."), 
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = g_polApp->Logon(NULL);
    if (hr != S_OK) {
        // Logon failed.
        MessageBox(NULL, 
                   _T("Logon failed."), 
                   _T("Warning"), 
                   MB_OK);
        pOutApp->Release();
        exit(0);  // Replace with specific error handling.;
    }

    bSuccess = TRUE;
    return bSuccess;
}

See Also

How to Create a PIM Application with POOM | Pocket Outlook Object Model Application Development for Windows Mobile-based Devices | IPOutlookApp::Logoff

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.