18,356
社区成员
发帖
与我相关
我的任务
分享
#import <cdosys.dll> no_namespace raw_interfaces_only
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#include "cdosysstr.h"
#include "cdosyserr.h"
#include <comdef.h>
...
IMessagePtr Load_Message_from_File(_bstr_t path)
{
/*
** This example shows a common use of the ADO Stream
** object with CDO, namely, opening a serialized
** message from a file on disk and loading it into
** a CDO Message object.
**/
_StreamPtr pStm(__uuidof(Stream));
_variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
try {
pStm->Open(
// pStm->raw_Open(
varOptional,
adModeUnknown,
adOpenStreamUnspecified,
NULL,
NULL);
pStm->LoadFromFile(path);
}
catch(_com_error e)
{
throw e;
}
IMessagePtr iMsg(__uuidof(Message));
IDataSourcePtr iDsrc;
iDsrc = iMsg;
try {
iDsrc->OpenObject(pStm,_bstr_t("_Stream"));
}
catch(_com_error e)
{
throw e;
}
return iMsg;
}
void GetFrom()
{
IMessagePtr imsgptr=Load_Message_from_File("c:\\test.eml");
BSTR bsfrom;
imsgptr->get_From(&bsfrom);
_bstr_t bfrom(bsfrom);
AfxMessageBox(bfrom);
}