Share via


How to: Establish a POOM Session

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

To establish a 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 Pocket Outlook application interface object:

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

    g_polApp->Logon(NULL);
    

Example

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

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

IPOutlookApp::Logoff

Pocket Outlook Object Model

Last updated on Friday, April 22, 2005

© 2005 Microsoft Corporation. All rights reserved.

Send feedback on this topic to the authors.