Share via


IMAPISession::GetMsgStoresTable

Send Feedback

The GetMsgStoresTable method provides access to the message store table, which contains information about all of the message stores in the session profile.

Syntax

HRESULT GetMsgStoresTable (
  ULONG ulFlags,
  LPMAPITABLE FAR * lppTable
);

Parameters

  • ulFlags
    [in] Ignored.
  • lppTable
    [out] Reference to the message store table, implemented on IMAPITable.

Return Values

This method returns the standard values E_INVALIDARG, E_OUTOFMEMORY, E_UNEXPECTED, and E_FAIL, as well as the following:

  • S_OK
    Indicates success.

Remarks

GetMsgStoresTable retrieves a pointer to the message store table, a table maintained by MAPI that contains information about each open message store in the profile.

The following IMAPITable methods are supported for message store tables in Windows Mobile Messaging:

Because MAPI updates the message store table during the session whenever changes occur, call the IMapiSession::Advise method to register to be notified of these changes. Possible changes include the addition of new message stores, removal of existing stores, and changes to the default store.

For an example of how to use this method, see the Sending e-mail code sample.

Code Example

The following code example demonstrates how to use GetMsgStoresTable.

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.

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int CmdShow)
{
    HRESULT             hr;
    IMAPISession    *   pSession    =   NULL;
    IMAPITable      *   pTable      =   NULL;
    SRowSet         *   psrs        =   NULL;
    IMsgStore       *   pStore      =   NULL;
    ULONG               rgTags[]    =   { 1, PR_CE_IPM_DRAFTS_ENTRYID };
    ULONG               cValues     =   0;
    SPropValue      *   rgprops     =   NULL;
    SPropValue      *   rgpropsMsg  =   NULL;
    LPMAPIFOLDER        pfldrDrafts =   NULL;
    IMessage        *   pmsg        =   NULL;

    // Logon to the store.
    hr = MAPILogonEx(NULL, NULL, NULL, NULL, &pSession);

    // Get the message stores table.
    hr = pSession->GetMsgStoresTable(MAPI_UNICODE, &pTable);

    while (SUCCEEDED(pTable->QueryRows(1, 0, &psrs)))
    {
        // Check number of rows returned. Since the above call only asks for one, anything else means we are at the end of the table.
        if (1 != psrs->cRows)
            break;

        // Make sure to get all the properties that you need.
        if ((1 > psrs->aRow[0].cValues)||(PR_ENTRYID != psrs->aRow[0].lpProps[0].ulPropTag))
        {
            MessageBox(NULL, L"Store missing PR_ENTRYID!", L"Error", MB_OK);
            hr = E_FAIL;
            break;
        }

        // Open this message store.
        hr = pSession->OpenMsgStore(NULL, psrs->aRow[0].lpProps[0].Value.bin.cb, (ENTRYID *)psrs->aRow[0].lpProps[0].Value.bin.lpb, NULL, 0, &pStore);

        // Get the Drafts folder. For a message to be sent by MAPI, it must be created in the Drafts folder.
        hr = pStore->GetProps((SPropTagArray *)rgTags, MAPI_UNICODE, &cValues, &rgprops);

        ASSERT(rgprops);
        ASSERT(rgprops[0].ulPropTag == PR_CE_IPM_DRAFTS_ENTRYID);

        hr = pStore->OpenEntry(rgprops[0].Value.bin.cb, (LPENTRYID)rgprops[0].Value.bin.lpb, NULL, MAPI_MODIFY, NULL, reinterpret_cast <IUnknown **>(&pfldrDrafts));

        ASSERT(pfldrDrafts);

        // Create a message.
        hr = pfldrDrafts->CreateMessage(NULL, 0, &pmsg);
        ASSERT(pmsg);

        // Set the some properies on the message.
        CEMAPI_SetMessageProps(pmsg);

        // attach a bogus file.
        hr=CEMAPI_AttachFile(pmsg);

        // Send the message.
        hr = pmsg->SubmitMessage(0);

        // Clean up
        MAPIFreeBuffer(rgprops);
        MAPIFreeBuffer(rgpropsMsg);
        FreeProws(psrs);
        
        rgprops     =   NULL;
        rgpropsMsg  =   NULL;
        psrs        =   NULL;

        RELEASE_OBJ(pmsg);
        RELEASE_OBJ(pfldrDrafts);
        RELEASE_OBJ(pStore);
    }

FuncExit:
    //Clean up
    MAPIFreeBuffer(rgprops);
    MAPIFreeBuffer(rgpropsMsg);
    FreeProws(psrs);

    RELEASE_OBJ(pmsg);
    RELEASE_OBJ(pfldrDrafts);
    RELEASE_OBJ(pStore);
    RELEASE_OBJ(pTable);
    RELEASE_OBJ(pSession);

    return 0;

}

Requirements

Pocket PC: Pocket PC 2002 and later
Smartphone: Smartphone 2002 and later
OS Versions: Windows CE 3.0 and later
Header: mapix.h
Library: cemapi.lib

See Also

IMAPISession | IMAPISession::OpenMsgStore | Messaging

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.