Algorithm to Calculate the Store Hash Number

Algorithm to Calculate the Store Hash Number

As part of a MAPI Uniform Resource Locator (URL), a store provider sends a store hash number to the MAPI Protocol Handler to identify an object that is ready for indexing. The MAPI Protocol Handler uses this store hash number to identify a store. In general, a store provider calculates the store hash number based on the store mapping signature, if the store has the PR_MAPPING_SIGNATURE property defined in the global profile section. Otherwise, the store provider uses the store entry ID. The algorithm to calculate the store hash number must minimize ambiguities identifying stores.

This topic describes an algorithm that Microsoft Office Outlook uses to calculate a store hash number based on the store entry ID and the store file name.

  DWORD ComputeStoreHash(ULONG cbStoreEID, LPENTRYID pbStoreEID, LPCWSTR pwzFileName)
    DWORD  dwHash = 0;
    ULONG  cdw    = 0;
    DWORD* pdw    = NULL;
    ULONG  cb     = 0;
    BYTE*  pb     = NULL;
    ULONG  i      = 0;
    // Get the Store Entry ID
    // pbStoreEID is a pointer to the Entry ID
    // cbStoreEID is the size in bytes of the Entry ID
    pdw = (DWORD*)pbStoreEID;
    cdw = cbStoreEID / sizeof(DWORD);
    for (i = 0; i < cdw; i++)
        dwHash = (dwHash << 5) + dwHash + *pdw++;
    pb = (BYTE *)pdw;
    cb = cbStoreEID % sizeof(DWORD);
    for (i = 0; i < cb; i++)
        dwHash = (dwHash << 5) + dwHash + *pb++;
    // You may want to also include the store file name in the hash calculation
    // Get store FileName
    // pwzFileName is a NULL terminated string with the path and filename of the store
    if (pwzFileName)
        while (*pwzFileName)
            dwHash = (dwHash << 5) + dwHash + *pwzFileName++;
// dwHash now contains the hash to be used. It should be written in hex when building the URL.
return dwHash;


See Also

About Notification-Based Store Indexing

About MAPI URLs for Notification-Based Indexing