Indian_Techie
July 12th, 2002, 02:19 PM
hi gurus,
right now i'm stuck in one problem. i am creating new mail-accounts form my application (for PPC-2002 inbox). everything goes well and the account is getting created. when i run inbox, i can see the new account and i can also receive and send mails. but i want to set Name field (display name) from my app. by default, its taking mail-address as name. i dont know how to set the name property. i'm trying with IMsgStore::SetProps function. but its of no use. but i still have a gut feeling that this is the function that will get the work done. its only that i am not able to use it properly. can someone help me out please?
i'm just giving a function that creates the service folder.. and after this i do lotta raw coding like writing in the registry and stuff like that as i really dont see any proper documentation for 2002. i think the basic problem lies in this function..
i'm giving the code below... ofcourse this code alone is not enough for testing.. but if someone can find problem by looking at the code it self, it would be great! else i can send the whole project (its a dll).
thanks for any help!
john.
LONG addServiceFolder(LPCTSTR serviceName, BYTE*& msgStoreID, int& cbID)
{
HRESULT hRc;
IMsgStore* ms;
msgStoreID = 0;
hRc = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hRc))
{
MessageBox(0, _T("CoInitializeEx Failed"), 0, 0);
return hRc;
}
hRc = MAPIInitialize(0);
if (FAILED(hRc))
{
MessageBox(0, _T("MAPIInitialize Failed"), 0, 0);
return hRc;
}
ICEMAPISession* session;
hRc = MAPILogonEx(0, 0, 0, 0, (IMAPISession**)&session);
if (FAILED(hRc))
{
MessageBox(0, _T("MAPILogonEx Failed"), 0, 0);
return hRc;
}
hRc = session->CreateMsgStore(serviceName, &ms);
if (FAILED(hRc) || !ms)
{
MessageBox(0, _T("CreateMsgStore Failed"), 0, 0);
return hRc;
}
DWORD cProps;
SPropValue* propArray;
struct
{
SPropTagArray propTag;
//ULONG val2;
} tag;
tag.propTag.cValues = 1;
tag.propTag.aulPropTag[0] = PR_ENTRYID;
hRc = ms->GetProps((SPropTagArray*)&tag, MAPI_UNICODE, &cProps, &propArray);
if (FAILED(hRc))
{
MessageBox(0, _T("GetProps Failed"), 0, 0);
return hRc;
}
///////////////////// added code for Name property//////////////////////////
WCHAR* name = {NULL};
SPropValue propVal;
SPropValue* propArray2;
DWORD cProps2;
struct
{
SPropTagArray propTag;
//ULONG val2;
} tag2;
tag2.propTag.cValues = 1;
tag2.propTag.aulPropTag[0] = PR_SENDER_NAME; // tried PR_SENDER_NAME_W as well
hRc = ms->GetProps((SPropTagArray*)&tag2, MAPI_UNICODE, &cProps2, &propArray2);
if (FAILED(hRc))
{
MessageBox(0, _T("GetProps failed for PR_SENDER_NAME"), 0, 0);
return hRc;
}
propArray2[0].dwAlignPad = 0;
propArray2[0].ulPropTag = PR_SENDER_NAME;
propArray2[0].Value.lpszW = new WCHAR[255]; // i'm not sure if its correct to assign memory here..
wcscpy(propArray2[0].Value.lpszW, _T("John"));
hRc = ms->SetProps(cProps2, propArray2, 0);
if (FAILED(hRc))
{
MessageBox(0, _T("SetProps failed for PR_SENDER_NAME"), 0, 0);
return hRc;
}
if (cProps!=1)
{
MessageBox(0, _T("cProps !=1"), 0, 0);
return -1;
}
SPropValue v = propArray[0];
if (v.ulPropTag != PR_ENTRYID)
{
MessageBox(0, _T("ulPropTag is not PR_ENTRYID"), 0, 0);
return -1;
}
if (v.Value.bin.cb != 16)
{
MessageBox(0, _T("v.Value.bin.cb is not 16"), 0, 0);
return -1;
}
if (!v.Value.bin.lpb)
{
MessageBox(0, _T("v.Value.bin.lpb is NULL"), 0, 0);
return -1;
}
msgStoreID = new BYTE[v.Value.bin.cb];
ASSERT(msgStoreID);
if (!msgStoreID)
{
MessageBox(0, _T("Failed to allocate memory for msgStoreID"), 0, 0);
return -1;
}
memcpy(msgStoreID, v.Value.bin.lpb, v.Value.bin.cb);
cbID = v.Value.bin.cb;
MAPIFreeBuffer(propArray);
delete [] propArray2[0].Value.lpszW; // i'm not sure if its correct to delete here..
ms->Release();
session->Logoff(0, 0, 0);
session->Release();
MAPIUninitialize();
CoUninitialize();
return S_OK;
}
right now i'm stuck in one problem. i am creating new mail-accounts form my application (for PPC-2002 inbox). everything goes well and the account is getting created. when i run inbox, i can see the new account and i can also receive and send mails. but i want to set Name field (display name) from my app. by default, its taking mail-address as name. i dont know how to set the name property. i'm trying with IMsgStore::SetProps function. but its of no use. but i still have a gut feeling that this is the function that will get the work done. its only that i am not able to use it properly. can someone help me out please?
i'm just giving a function that creates the service folder.. and after this i do lotta raw coding like writing in the registry and stuff like that as i really dont see any proper documentation for 2002. i think the basic problem lies in this function..
i'm giving the code below... ofcourse this code alone is not enough for testing.. but if someone can find problem by looking at the code it self, it would be great! else i can send the whole project (its a dll).
thanks for any help!
john.
LONG addServiceFolder(LPCTSTR serviceName, BYTE*& msgStoreID, int& cbID)
{
HRESULT hRc;
IMsgStore* ms;
msgStoreID = 0;
hRc = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hRc))
{
MessageBox(0, _T("CoInitializeEx Failed"), 0, 0);
return hRc;
}
hRc = MAPIInitialize(0);
if (FAILED(hRc))
{
MessageBox(0, _T("MAPIInitialize Failed"), 0, 0);
return hRc;
}
ICEMAPISession* session;
hRc = MAPILogonEx(0, 0, 0, 0, (IMAPISession**)&session);
if (FAILED(hRc))
{
MessageBox(0, _T("MAPILogonEx Failed"), 0, 0);
return hRc;
}
hRc = session->CreateMsgStore(serviceName, &ms);
if (FAILED(hRc) || !ms)
{
MessageBox(0, _T("CreateMsgStore Failed"), 0, 0);
return hRc;
}
DWORD cProps;
SPropValue* propArray;
struct
{
SPropTagArray propTag;
//ULONG val2;
} tag;
tag.propTag.cValues = 1;
tag.propTag.aulPropTag[0] = PR_ENTRYID;
hRc = ms->GetProps((SPropTagArray*)&tag, MAPI_UNICODE, &cProps, &propArray);
if (FAILED(hRc))
{
MessageBox(0, _T("GetProps Failed"), 0, 0);
return hRc;
}
///////////////////// added code for Name property//////////////////////////
WCHAR* name = {NULL};
SPropValue propVal;
SPropValue* propArray2;
DWORD cProps2;
struct
{
SPropTagArray propTag;
//ULONG val2;
} tag2;
tag2.propTag.cValues = 1;
tag2.propTag.aulPropTag[0] = PR_SENDER_NAME; // tried PR_SENDER_NAME_W as well
hRc = ms->GetProps((SPropTagArray*)&tag2, MAPI_UNICODE, &cProps2, &propArray2);
if (FAILED(hRc))
{
MessageBox(0, _T("GetProps failed for PR_SENDER_NAME"), 0, 0);
return hRc;
}
propArray2[0].dwAlignPad = 0;
propArray2[0].ulPropTag = PR_SENDER_NAME;
propArray2[0].Value.lpszW = new WCHAR[255]; // i'm not sure if its correct to assign memory here..
wcscpy(propArray2[0].Value.lpszW, _T("John"));
hRc = ms->SetProps(cProps2, propArray2, 0);
if (FAILED(hRc))
{
MessageBox(0, _T("SetProps failed for PR_SENDER_NAME"), 0, 0);
return hRc;
}
if (cProps!=1)
{
MessageBox(0, _T("cProps !=1"), 0, 0);
return -1;
}
SPropValue v = propArray[0];
if (v.ulPropTag != PR_ENTRYID)
{
MessageBox(0, _T("ulPropTag is not PR_ENTRYID"), 0, 0);
return -1;
}
if (v.Value.bin.cb != 16)
{
MessageBox(0, _T("v.Value.bin.cb is not 16"), 0, 0);
return -1;
}
if (!v.Value.bin.lpb)
{
MessageBox(0, _T("v.Value.bin.lpb is NULL"), 0, 0);
return -1;
}
msgStoreID = new BYTE[v.Value.bin.cb];
ASSERT(msgStoreID);
if (!msgStoreID)
{
MessageBox(0, _T("Failed to allocate memory for msgStoreID"), 0, 0);
return -1;
}
memcpy(msgStoreID, v.Value.bin.lpb, v.Value.bin.cb);
cbID = v.Value.bin.cb;
MAPIFreeBuffer(propArray);
delete [] propArray2[0].Value.lpszW; // i'm not sure if its correct to delete here..
ms->Release();
session->Logoff(0, 0, 0);
session->Release();
MAPIUninitialize();
CoUninitialize();
return S_OK;
}