Hi Dmitry!
On Mon, 17 Nov 2003 11:32:01 -0700, "Dmitry Streblechenko"
Post by Dmitry StreblechenkoYes, that is exactly what named propertis are for - call
IMessage::GetIDsFromNames() passing your own GUID and ids (strings or
integers), then "or" the returned tag with the correct type (PT_xxx). The
resulting tag is guaranteed to be unique in a particular message store.
Cool! After some research, I came up with the following code (parts are
courtesy of Microsoft):
bool char2wchar(const char* psz, WCHAR** ppwsz)
{
assert(psz);
assert(ppwsz);
WCHAR* pwsz=NULL;
int iwLen;
iwLen=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, psz, -1, NULL, 0); // calculate number of WCHARS necessary
if(!(pwsz=new WCHAR[iwLen+1])) goto err; // allocate mem
if(iwLen!=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, psz, -1, pwsz, iwLen)) goto err;
*ppwsz=pwsz; // return wide version
return true;
err:
if(pwsz) delete[] pwsz;
return false;
}
HRESULT MAPI_ProptagFromString(IMAPIProp* lpProp, const char* lpszPropName, const ULONG ulPropType, ULONG *pulPropTag)
{
HRESULT hr=NOERROR;
MAPINAMEID nameid={0};
MAPINAMEID *rgpnameid[1]={&nameid};
WCHAR* pwsz=NULL;
_SPropTagArray* lpSPropTags=NULL;
if(!char2wchar(lpszPropName, &pwsz)) // Convert property tag string to Unicode
{
hr=E_FAIL;
goto err;
}
nameid.lpguid = (GUID*)&PS_PUBLIC_STRINGS;
nameid.ulKind = MNID_STRING;
nameid.Kind.lpwstrName = pwsz;
hr=lpProp->GetIDsFromNames(1, rgpnameid, MAPI_CREATE, &lpSPropTags);
if(FAILED(hr)) goto err;
*pulPropTag = lpSPropTags->aulPropTag[0];
*pulPropTag = PROP_TAG( ulPropType, PROP_ID(*pulPropTag)); // Change PT_UNSPECIFIED to the type required by the user
err:
if(pwsz) delete[] pwsz;
MAPIFreeBuffer(lpSPropTags);
return hr;
}
Looks nice to OutlookSpy your own properties (complete with
"description") in a message! :-)
Thanks for your help!
Volker
Post by Dmitry StreblechenkoPost by Volker BartheldHell - I'm setting it to IPM.note.PROCESSED to signalize that my ece
shouldn't bother with it anymore. Just changed it back to IPM.note and
the envelope opened. Voila!
So I'm better advised with introducing a new property for my own
purpose. How do you suggest doing that without interfering with
properties that are already there? Is there some kind of "user
namespace" for user defined properties?