none
Por que não consigo pegar nada da mensagem? RRS feed

  • Pergunta

  • Code Snippet

    #import "F:\Arquivos de programas\Arquivos comuns\System\ado\msado15.dll" rename("EOF", "AdoEOF"), no_namespace
    #import <cdosys.dll> no_namespace
    #include <comdef.h>

    void EmbedMessage( IMessagePtr iMsg, IBodyPartPtr iBp)
    {
    IDataSourcePtr iDsrc;
    iDsrc = iMsg;

    try
    {
    iDsrc->SaveToObject(iBp,_bstr_t("IBodyPart"));
    }
    catch(_com_error error)
    {
    throw error;
    }

    }

    IMessagePtr ExtractMessage(IBodyPartPtr iBp)
    {
    IMessagePtr iMsg(__uuidof(Message));
    IDataSourcePtr iDsrc;
    iDsrc = iMsg;

    try
    {
    iDsrc->OpenObject(iBp,_bstr_t("IBodyPart"));
    }
    catch(_com_error error)
    {
    throw error;
    }
    return iMsg;

    }

    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->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 Save_Message_to_File(IMessagePtr iMsg, bstr_t filename)
    {
    /*
    ** This example shows a common use of the ADO Stream
    ** object with CDO, namely, saving a serialized
    ** message to disk using an ADO Stream object.
    **/
    _StreamPtr pStm(__uuidof(Stream));
    IDataSourcePtr iDsrc;
    iDsrc = iMsg;

    _variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
    pStm->Open(
    varOptional,
    adModeUnknown,
    adOpenStreamUnspecified,
    _bstr_t(""),
    _bstr_t(""));
    pStm->Type = adTypeText;
    pStm->Charset = "US-ASCII"; // apparently, we need this!
    try
    {
    iDsrc->SaveToObject(pStm,_bstr_t("_Stream"));
    }
    catch(_com_error error)
    {
    throw error;
    }

    try {
    pStm->SaveToFile(filename,adSaveCreateOverWrite);
    }
    catch(_com_error e)
    {
    throw e;
    }
    }

    int main(int argc, char* argv[])
    {
    CoInitialize(NULL);

    IMessage* pMsg2 = Load_Message_from_File(_bstr_t("D:\\teste.eml"));

    _bstr_t bsNome= pMsg2->GetSubject();

    pMsg2->Release();

    CoUninitialize();
    }


    terça-feira, 14 de outubro de 2008 14:55