// Note: Mapi32.lib is required to successfully compile and link
// the following code.
#include <mapix.h>
#include <mapiutil.h>
#include <stdio.h>
HRESULT hr = S_OK;
LPMAPISESSION lpSession = NULL;
LPMAPITABLE lpStatusTable = NULL;
SRestriction sres;
SPropValue spvResType;
LPSRowSet pRows = NULL;
LPTSTR lpszProfileName = NULL;
SizedSPropTagArray(2, Columns) =
{
2, PR_DISPLAY_NAME, PR_RESOURCE_TYPE
};
hr = MAPIInitialize(NULL);
// Log on to the Extended MAPI session.
hr = MAPILogonEx((ULONG)GetActiveWindow(),
NULL,
NULL,
MAPI_LOGON_UI | MAPI_NEW_SESSION,
&lpSession);
hr = lpSession->GetStatusTable(NULL, &lpStatusTable);
hr = lpStatusTable->SetColumns((LPSPropTagArray)&Columns, NULL);
spvResType.ulPropTag = PR_RESOURCE_TYPE;
spvResType.Value.ul = MAPI_SUBSYSTEM;
sres.rt = RES_PROPERTY;
sres.res.resProperty.relop = RELOP_EQ;
sres.res.resProperty.ulPropTag = PR_RESOURCE_TYPE;
sres.res.resProperty.lpProp = &spvResType;
hr = lpStatusTable->Restrict(&sres, TBL_ASYNC);
hr = lpStatusTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);
// We have a match.
hr = lpStatusTable->QueryRows(1,0,&pRows);
if (SUCCEEDED(hr))
{
lpszProfileName = pRows->aRow[0].lpProps[0].Value.lpszA;
printf("You logged onto profile \"%s\"\n", lpszProfileName);
}