Hi All,
I have a small piece of code which opens the mail item, changes the
message class and adds an custom property to the message in the Exchange
2000
store. This code seems to be working fine as an "exe" with the message class
being changed and the custom property being added to the message.
If I convert the same code into a ATL dll and call the method from a
VB client, the code doesn't work as expected. Only the message class gets
changed.
Am I missing something??
System Details:
a) Windows 2000 server build 2195, SP2
a) Exchange 2000 server with SP2
Below is the code for reference:
---------------------------------------------------------------------
Headers.h
#import <msado15.dll> no_namespace rename("EOF", "EndOfFile")
#import <cdoex.dll> no_namespace
#include <objbase.h>
#include <iostream.h>
#include <string.h>
#include <assert.h>
#include <comdef.h>
#include <stdio.h>
----------------------------------------------------------------------------
------------
The "exe" code
Property.cpp
#include "Headers.h"
struct StartOle {
StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }
} _inst_StartOle;
void dump_com_error(_com_error &e)
{
printf("Oops - hit an error!\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s\n", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\tSource = %s\n", (LPCTSTR) bstrSource);
printf("\tDescription = %s\n", (LPCTSTR) bstrDescription);
}
int main(void)
{
HRESULT hr;
IMessagePtr iMsg = NULL;
IDataSourcePtr iDsrc = NULL;
bstr_t MailUrl;
_variant_t varOptional (DISP_E_PARAMNOTFOUND,VT_ERROR);
FieldsPtr Flds;
MailUrl="file://./backofficestorage/mydomain.com/MBX/vijay/Inbox/Hi.EML";
CoInitialize(NULL);
try
{
//Create an Instance of Message class
hr = CoCreateInstance( __uuidof(Message),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IMessage),
reinterpret_cast<void**>(&iMsg)
);
assert(SUCCEEDED(hr));
if (SUCCEEDED(hr))
{
cout << "Message instance created !"<< endl;
}
//Get the Datasource interface
iDsrc=iMsg;
//Open the mail
hr= iDsrc->Open(MailUrl,
NULL,
adModeReadWrite,
adFailIfNotExists,
adOpenSource,
bstr_t(),
bstr_t()
);
if (SUCCEEDED(hr))
{
cout<<"Opened the Mail"<<endl;
}
Flds=iMsg->Fields;
string str("IPM.Note1");
bstr_t xxx(str.c_str());
//Message Class
Flds->Item["http://schemas.microsoft.com/exchange/outlookmessageclass"]->Val
ue
= _variant_t(xxx);
Flds->Update();
//Custom Property
Flds->Append(bstr_t("Prop:Prop1"),adBSTR,1,static_cast<FieldAttributeEnum>(0
),_variant_t("MyProp") );
Flds->Update();
//Save these to the message
hr = iMsg->DataSource->Save();
if(SUCCEEDED(hr))
{
cout<<"Property Written"<<endl;
}
}// Try
catch( _com_error e)
{
dump_com_error(e);
}
CoUninitialize();
return 0;
}
----------------------------------------------------------------------------
------------
The ATL Dll code
#include "Headers.h"
STDMETHODIMP MyClass::SetProperty(BSTR mailUrl)
{
HRESULT hr;
IMessagePtr iMsg = NULL;
IDataSourcePtr iDsrc = NULL;
FieldsPtr Flds;
CoInitialize(NULL);
//*** Create an Instance of Message class /
hr = CoCreateInstance(__uuidof(Message),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IMessage),
reinterpret_cast<void**>(&iMsg)
);
assert(SUCCEEDED(hr));
if (SUCCEEDED(hr))
{
cout << "Message instance created !"<< endl;
}
//Get the Datasource interface
iDsrc=iMsg;
//Open the mail
hr= iDsrc->Open(MailUrl,
NULL,
adModeReadWrite,
adFailIfNotExists,
adOpenSource,
bstr_t(),
bstr_t()
);
if (SUCCEEDED(hr))
{
cout<<"Opened the Mail"<<endl;
}
Flds=iMsg->Fields;
string str("IPM.Note1");
bstr_t xxx(str.c_str());
//Message Class
Flds->Item["http://schemas.microsoft.com/exchange/outlookmessageclass"]->Val
ue
= _variant_t(xxx);
Flds->Update();
//Custom Property
Flds->Append(bstr_t("Prop:Prop1"),adBSTR,1,static_cast<FieldAttributeEnum>(0
),_variant_t("MyProp") );
Flds->Update();
//Save these to the message
hr = iMsg->DataSource->Save();
if(SUCCEEDED(hr))
{
cout<<"Property Written"<<endl;
}
CoUninitialize();
return S_OK;
}
P.S: The method "SetProperty" is called from a VB client
----------------------------------------------------------------------------
------------
Regards
Vijay
_________________________________________________________________
List posting FAQ: http://www.swinc.com/resource/exch_faq.htm
Archives: http://www.swynk.com/sitesearch/search.asp
To unsubscribe: mailto:[EMAIL PROTECTED]
Exchange List admin: [EMAIL PROTECTED]