Lm th? no ? m? m?t tin nh?n b?ng cch s? d?ng m h?nh ?i t?ng Outlook v?i m?c nh?p ID L?y t? MAPI trong Visual C++ 6.0

D?ch tiu ? D?ch tiu ?
ID c?a bi: 304894 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

GI?I THI?U

Bi vi?t ny ch?ng t? lm th? no ? s? d?ng PR_ENTRYID ti s?n thu ?c t? m? r?ng MAPI ? m? v hi?n th? kho?n m?c b?ng cch s? d?ng m?t s? M h?nh ?i t?ng Outlook.

THNG TIN THM

T?o v xy d?ng d? n m?u ny t?i Microsoft Visual C + +, lm theo cc b?c sau:
  1. M? Visual Studio, t?o ra m?t ?ng d?ng Win32 m?i ?t tn "OOMEntryID", v sau ch?n M?t ?ng d?ng n gi?n Win32.
  2. M? t?p tin OOMEntryID.cpp v thay th? ton b? c?a n n?i dung v?i m? d?i y. H?y ch?c ch?n r?ng b?n thay ?i ?ng d?n cho Mso.dll v Msoutl.olb ? tr? ?n v? tr tng ?ng c?a h? cho my tnh c?a b?n.
    #include "stdafx.h"
    #include "edk.h"
    
    // Import Outlook object model.
    #define IMPPROPS rename_namespace("OL")
    // Define this according to the Outlook object model 
    // version you are compiling under.
    
    //#define OL2000 // Outlook 2000
    #define OL2002 // Outlook 2002 (2002)
    
    #if defined(OL2000)
      // TODO: Verify that the path to the file is correct.
      #import "c:\Program Files\Microsoft Office\Office\mso9.dll" IMPPROPS 
      #import "c:\Program Files\Microsoft Office\Office\msoutl9.olb" IMPPROPS
    #elif defined(OL2002)
      // TODO: Verify that the path to the file is correct.
      #import "c:\Program Files\Common Files\Microsoft Shared\Office10\mso.dll" IMPPROPS 
      #import "c:\Program Files\Microsoft Office\Office10\\msoutl.olb" IMPPROPS
    #endif
    
    struct StartOle 
    {
       StartOle() { CoInitialize(NULL); }
       ~StartOle() { CoUninitialize(); }
    } _inst_StartOle;
    
    
    void dump_com_error(_com_error &e)
    {
        _tprintf(_T("Oops - hit an error!\n"));
        _tprintf(_T("\a\tCode = %08lx\n"), e.Error());
        _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());
        _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
        _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
    }
    
    using namespace OL;
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
      // MAPI session pointer.
      LPMAPISESSION  pSession = NULL; 
      HRESULT hRes = S_OK;
      
      // Please add error checking yourself.
    
      // Initialize MAPI.
      hRes = MAPIInitialize(NULL);
    
      // Log on to MAPI and get a session pointer.
      hRes = MAPILogonEx(0, NULL, NULL, MAPI_LOGON_UI, &pSession);
    
      // Open message store.
      ULONG      cbEIDStore = 0;
      LPENTRYID  lpEIDStore = NULL;
      IMsgStore  *pMsgStore;
    
      hRes = HrMAPIFindDefaultMsgStore(pSession, 
                      &cbEIDStore, 
                      &lpEIDStore);
    
      hRes = pSession->OpenMsgStore(NULL, 
                      cbEIDStore, 
                      lpEIDStore, 
                      NULL, 
                      MAPI_BEST_ACCESS, 
                      &pMsgStore);  
    
      // Open Inbox.
      ULONG        ulObjType;
      ULONG        cbEntryID;
      LPENTRYID    lppEntryID;
      IMAPIFolder  *lpFolder;
    
      hRes = pMsgStore->GetReceiveFolder(NULL, 
                         NULL, 
                         &cbEntryID, 
                         &lppEntryID, 
                         NULL);
    
      hRes = pMsgStore->OpenEntry(cbEntryID, 
                    lppEntryID, 
                    NULL, 
                    MAPI_BEST_ACCESS, 
                    &ulObjType, 
                    (LPUNKNOWN *)&lpFolder);
    
    
      // Get Inbox items.
      LPMAPITABLE  lpContentsTable = NULL;
      LPSRowSet    pRows = NULL;
      enum {ePR_SUBJECT, ePR_ENTRYID,  NUM_COLS};
      static SizedSPropTagArray(NUM_COLS,sptCols) 
      = {NUM_COLS, PR_SUBJECT, PR_ENTRYID};
      
    
      hRes = lpFolder->GetContentsTable(0, 
                        &lpContentsTable);
    
      hRes = HrQueryAllRows(lpContentsTable, 
                  (LPSPropTagArray) &sptCols, 
                  NULL, 
                  NULL, 
                  0, 
                  &pRows);
      
      if (pRows->cRows > 0) // Make sure there is at least one message.
      {
        // Get the first item in the Inbox and get its entry ID.
        IMessage    *lpMessage;
        LPSPropValue  pspvEID = NULL;
    
        hRes = pMsgStore->OpenEntry(pRows->aRow[0].lpProps[ePR_ENTRYID].Value.bin.cb, 
                                 (LPENTRYID)pRows->aRow[0].lpProps[ePR_ENTRYID].Value.bin.lpb, 
                                 NULL, 
                                 MAPI_BEST_ACCESS, 
                                 &ulObjType, 
                                 (LPUNKNOWN *)&lpMessage);
        
        hRes = HrGetOneProp(lpMessage, 
                  PR_ENTRYID, 
                  &pspvEID);
        
        char szEID[1001];
        HexFromBin(pspvEID[0].Value.bin.lpb, 
                   pspvEID[0].Value.bin.cb, 
                   szEID);
    
        // Open Outlook item using the entry ID we got from MAPI.
    
        try{
          OL::_ApplicationPtr  pOutlook("Outlook.Application");
          OL::_NameSpacePtr    pNameSpace = pOutlook->GetNamespace("MAPI");
          OL::_MailItemPtr     pMailItem = NULL;
    
          pMailItem = pNameSpace->GetItemFromID(szEID, vtMissing);
          if (pMailItem)
          {
            // Display message.
            pMailItem->Display(vtMissing);
          }
        } 
    
        catch (_com_error &e)
        {
          dump_com_error(e);
        }
    
        UlRelease(lpMessage);
      }
      else
      {
        MessageBox(NULL, 
               "There are no messages in the inbox", 
               "Open Item", 
               MB_OK);
      }
    
      pSession->Logoff(NULL, 0L, 0);
    
      FreeProws(pRows);
      UlRelease(lpContentsTable);
      UlRelease(lpFolder);
      UlRelease(pMsgStore);
      UlRelease(pSession);
    
      return 0;
    } 
    					
  3. Trn cc D an tr?nh n, nh?p vo Thit t. B?m vo cc Lin k?t tab, v sau ch?n ?u vo nh th? lo?i.

    ?i v?i cc ?i t?ng/th vi?n m-un ph?n, thm sau y.
    MSVCRT.LIB addrLkup.lib edkguid.lib edkdebug.lib edkmapi.lib edkutils.lib mapi32.lib
    						
    ?i v?i cc B? qua cc th vi?n o dan adran, thm libcd.lib v libc.lib.

    ng cc Thi?t l?p d? n h?p tho?i.
  4. Xy d?ng v sau ch?y cc d? n.
  5. Thng bo ?u tin trong h?p th ?n s? hi?n th?.

THAM KH?O

? bi?t thm thng tin, h?y b?m vao s? bi vi?t sau ? xem bi vi?t trong C s? Ki?n th?c Microsoft:
259298Lm th? no ? s? d?ng m?t m h?nh ?i t?ng Outlook t? Visual C++ b?ng cch s? d?ng m?t tuyn b? #import

Thu?c tnh

ID c?a bi: 304894 - L?n xem xt sau cng: 27 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Messaging Application Programming Interface
  • Microsoft Outlook 2000 Standard Edition
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Visual Studio 6.0 Enterprise Edition
T? kha:
kbemail kbopenfile kbprogramming kbhowto kbmsg kbmt KB304894 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:304894

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com