Lm th? no ? ?c thu?c tnh ti li?u h?p ch?t tr?c ti?p v?i VC ++

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

? Trang ny

TM T?T

B?n c th? l?y cc thu?c tnh ti li?u h?p ch?t t? m?t ti li?u b?ng cch s? d?ng tiu chu?n giao di?n m khng c my ch? ch?y ho?c th?m ch ang ?c ci ?t. Cho V d?, b?n c th? l?y cc thu?c tnh ?c xy d?ng trong ti li?u nh l tc gi?, Th?i gian qua l?n, v thu?c tnh trang Count m?t Microsoft vn ph?ng 97 ti li?u c?ng nh cc thu?c tnh tu? ch?nh ti li?u khc.

THNG TIN THM

Cc b?c sau y minh h?a nh th? no b?n c th? xy d?ng m?t ti li?u h?p ch?t b?t ?ng s?n ng?i xem v?i Microsoft Visual C++. V d? l m?t giao di?n i?u khi?n Win32 ?ng d?ng d? n, v c th? s?a ?i cho ph h?p v?i nhu c?u c?a b?n.

Cc b?c ? t?o m?u

  1. T?o m?t d? n Win32 giao di?n i?u khi?n ?ng d?ng m?i, v g?i n l PropDump.
  2. Thm m?t t?p tin m?i ?c g?i l main.cpp ? d? n c?a b?n.
  3. Copy o?n m? sau vo main.cpp:
       #include <stdio.h>
       #include <windows.h>
       #include <ole2.h>
       #include <locale.h>
    
    
    
       // Dumps simple PROPVARIANT values.
       void DumpPropVariant(PROPVARIANT *pPropVar) {
          // Don't iterate arrays, just inform as an array.
          if(pPropVar->vt & VT_ARRAY) {
             printf("(Array)\n");
             return;
          }
    
          // Don't handle byref for simplicity, just inform byref.
          if(pPropVar->vt & VT_BYREF) {
             printf("(ByRef)\n");
             return;
           }
    
          // Switch types.
          switch(pPropVar->vt) {
          case VT_EMPTY:
             printf("(VT_EMPTY)\n");
             break;
          case VT_NULL:
             printf("(VT_NULL)\n");
             break;
          case VT_BLOB:
             printf("(VT_BLOB)\n");
             break;
          case VT_BOOL:
             printf("%s (VT_BOOL)\n",
             pPropVar->boolVal ? "TRUE/YES" : "FALSE/NO");
             break;
          case VT_I2: // 2-byte signed int.
             printf("%d (VT_I2)\n", (int)pPropVar->iVal);
             break;
          case VT_I4: // 4-byte signed int.
             printf("%d (VT_I4)\n", (int)pPropVar->lVal);
             break;
          case VT_R4: // 4-byte real.
             printf("%.2lf (VT_R4)\n", (double)pPropVar->fltVal);
             break;
          case VT_R8: // 8-byte real.
             printf("%.2lf (VT_R8)\n", (double)pPropVar->dblVal);
             break;
             case VT_BSTR: // OLE Automation string.
             {
                // Translate into ASCII.
                char dbcs[1024];
                char *pbstr = (char *)pPropVar->bstrVal;
                int i = wcstombs(
                dbcs, pPropVar->bstrVal, *((DWORD *)(pbstr-4)));
                dbcs[i] = 0;
                printf("%s (VT_BSTR)\n", dbcs);
             }
             break;
          case VT_LPSTR: // Null-terminated string.
             {
             printf("%s (VT_LPSTR)\n", pPropVar->pszVal);
             }
             break;
          case VT_FILETIME:
             {
                char *dayPre[] =
                             {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
    
                FILETIME lft;
                FileTimeToLocalFileTime(&pPropVar->filetime, &lft);                SYSTEMTIME lst;
                FileTimeToSystemTime(&lft, &lst);
    
                printf("%02d:%02d.%02d %s, %s %02d/%02d/%d (VT_FILETIME)\n",
                   1+(lst.wHour-1)%12, lst.wMinute, lst.wSecond,
                   (lst.wHour>=12) ? "pm" : "am",
                   dayPre[lst.wDayOfWeek%7],
                   lst.wMonth, lst.wDay, lst.wYear);
             }
             break;
          case VT_CF: // Clipboard format.
             printf("(Clipboard format)\n");
    
             break;
          default: // Unhandled type, consult wtypes.h's VARENUM structure.
             printf("(Unhandled type: 0x%08lx)\n", pPropVar->vt);
             break;
          }
       }
    
       // Dump's built-in properties of a property storage.
       void DumpBuiltInProps(IPropertySetStorage *pPropSetStg) {
          printf("\n==================================================\n");
          printf("BuiltInProperties Properties...\n");
          printf("==================================================\n");
    
          IPropertyStorage *pPropStg = NULL;
          HRESULT hr;
    
          // Open summary information, getting an IpropertyStorage.
          hr = pPropSetStg->Open(FMTID_SummaryInformation,
          STGM_READ | STGM_SHARE_EXCLUSIVE, &pPropStg);
          //hr = pPropSetStg->Open(FMTID_UserDefinedProperties,
             //STGM_READ | STGM_SHARE_EXCLUSIVE, &pPropStg);
          if(FAILED(hr)) {
             printf("No Summary-Information.\n");
             return;
          }
          // Array of PIDSI's you are interested in.
          struct pidsiStruct {
             char *name;
             long pidsi;
          } pidsiArr[] = {
             {"Title",            PIDSI_TITLE}, // VT_LPSTR
             {"Subject",          PIDSI_SUBJECT}, // ...
             {"Author",           PIDSI_AUTHOR},
             {"Keywords",         PIDSI_KEYWORDS},
             {"Comments",         PIDSI_COMMENTS},
             {"Template",         PIDSI_TEMPLATE},
             {"LastAuthor",       PIDSI_LASTAUTHOR},
             {"Revision Number",  PIDSI_REVNUMBER},
             {"Edit Time",        PIDSI_EDITTIME}, // VT_FILENAME (UTC)
             {"Last printed",     PIDSI_LASTPRINTED}, // ...
             {"Created",          PIDSI_CREATE_DTM},
             {"Last Saved",       PIDSI_LASTSAVE_DTM},
             {"Page Count",       PIDSI_PAGECOUNT}, // VT_I4
             {"Word Count",       PIDSI_WORDCOUNT}, // ...
             {"Char Count",       PIDSI_CHARCOUNT},
    
             {"Thumpnail",        PIDSI_THUMBNAIL}, // VT_CF
             {"AppName",          PIDSI_APPNAME}, // VT_LPSTR
             {"Doc Security",     PIDSI_DOC_SECURITY}, // VT_I4
             {0, 0}
          };
          // Count elements in pidsiArr.
          int nPidsi = 0;
          for(nPidsi=0; pidsiArr[nPidsi].name; nPidsi++);
    
          // Initialize PROPSPEC for the properties you want.
          PROPSPEC *pPropSpec = new PROPSPEC [nPidsi];
          PROPVARIANT *pPropVar = new PROPVARIANT [nPidsi];
    
          for(int i=0; i<nPidsi; i++) {
             ZeroMemory(&pPropSpec[i], sizeof(PROPSPEC));
             pPropSpec[i].ulKind = PRSPEC_PROPID;
             pPropSpec[i].propid = pidsiArr[i].pidsi;
          }
    
    
    
          // Read properties.
          hr = pPropStg->ReadMultiple(nPidsi, pPropSpec, pPropVar);
    
          if(FAILED(hr)) {
             printf("IPropertyStg::ReadMultiple() failed w/error %08lx\n",
                    hr);
          }
          else {
             // Dump properties.
             for(i=0; i<nPidsi; i++) {
                printf("%16s: ", pidsiArr[i].name);
                DumpPropVariant(pPropVar + i);
             }
          }
    
          // De-allocate memory.
          delete [] pPropVar;
          delete [] pPropSpec;
    
          // Release obtained interface.
          pPropStg->Release();
    
       }
    
       // Dump's custom properties of a property storage.
       void DumpCustomProps(IPropertySetStorage *pPropSetStg) {
          printf("\n==================================================\n");
          printf("Custom Properties...\n");
          printf("==================================================\n");
    
          IPropertyStorage *pPropStg = NULL;
          HRESULT hr;
          IEnumSTATPROPSTG *pEnumProp;
    
          // Open User-Defined-Properties, getting an IpropertyStorage.
          hr = pPropSetStg->Open(FMTID_UserDefinedProperties,
             STGM_READ | STGM_SHARE_EXCLUSIVE, &pPropStg);
          if(FAILED(hr)) {
             printf("No User Defined Properties.\n");
             return;
          }
    
          // Get property enumerator.
          hr = pPropStg->Enum(&pEnumProp);
          if(FAILED(hr)) {
          pPropStg->Release();
             printf("Couldn't enumerate custom properties.\n");
             return;
          }
    
          // Enumerate properties.
          STATPROPSTG sps;
          ULONG fetched;
          PROPSPEC propSpec[1];
          PROPVARIANT propVar[1];
          while(pEnumProp->Next(1, &sps, &fetched) == S_OK) {
             // Build a PROPSPEC for this property.
             ZeroMemory(&propSpec[0], sizeof(PROPSPEC));
             propSpec[0].ulKind = PRSPEC_PROPID;
             propSpec[0].propid = sps.propid;
    
             // Read this property.
    
             hr = pPropStg->ReadMultiple(1, &propSpec[0], &propVar[0]);
             if(!FAILED(hr)) {
                // Translate Prop name into ASCII.
                char dbcs[1024];
                char *pbstr = (char *)sps.lpwstrName;
                int i = wcstombs(dbcs, sps.lpwstrName,
                                 *((DWORD *)(pbstr-4)));
                dbcs[i] = 0;
    
                // Dump this property.
                printf("%16s: ", dbcs);
                DumpPropVariant(&propVar[0]);
             }
          }
    
          // Release obtained interface.
          pEnumProp->Release();
          pPropStg->Release();
    
       }
    
       // Dump's custom and built-in properties of a compound document.
       void DumpProps(char *filename) {
          // Translate filename to Unicode.
          WCHAR wcFilename[1024];
          setlocale( LC_ALL, "" );
          int i = mbstowcs(wcFilename, filename, strlen(filename));
          setlocale( LC_ALL, "C" );
          wcFilename[i] = 0;
    
          IStorage *pStorage = NULL;
          IPropertySetStorage *pPropSetStg = NULL;
          HRESULT hr;
    
          // Open the document as an OLE compound document.
          hr = ::StgOpenStorage(wcFilename, NULL,
          STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
    
          if(FAILED(hr)) {
             if(hr == STG_E_FILENOTFOUND)
                printf("File not found.");
             else if(hr == STG_E_FILEALREADYEXISTS)
                printf("Not a compound file.");
             else
                printf("StgOpenStorage() failed w/error %08lx", hr);
             return;
          }
    
          // Obtain the IPropertySetStorage interface.
          hr = pStorage->QueryInterface(
                  IID_IPropertySetStorage, (void **)&pPropSetStg);
          if(FAILED(hr)) {
             printf("QI for IPropertySetStorage failed w/error %08lx", hr);
             pStorage->Release();
             return;
          }
    
          // Dump properties.
          DumpBuiltInProps(pPropSetStg);
          DumpCustomProps(pPropSetStg);
    
          // Release obtained interfaces.
          pPropSetStg->Release();
          pStorage->Release();
       }
    
       // Program entry-point.
       void main(int argc, char **argv) {
          // Validate arguments.
          if(argc != 2) {
             printf("- OLE Document Property Viewer\n");
             printf("- Usage: %s filename", argv[0]);
             return;
          }
    
          // Pass filename to the subroutine.
          DumpProps(argv[1]);
       }
    					
  4. Bin d?ch chng tr?nh.
? ch?y cc v d?, b?n nn sao chp cc t?p tin PropDump.exe vo m?t th m?c trong ?ng d?n m?c ?nh c?a b?n; V d? c:\Windows\ ho?c c:\Windows\Command\. Sau , trong m?t th m?c c ch?a m?t t?p tin h?p ch?t ti li?u, lo?i PropDump theo sau tn t?p tin. B?n s? th?y ?u ra tng t? nh sau:

==================================================

Thu?c tnh BuiltInProperties...

           Title: MyTitle (VT_LPSTR)
         Subject: MySubject (VT_LPSTR)
          Author: MyAuthor (VT_LPSTR)
        Keywords: MyKeywords (VT_LPSTR)
        Comments: MyComments (VT_LPSTR)
        Template: Normal (VT_LPSTR)
      LastAuthor: Me (VT_LPSTR)

 Revision Number: 8 (VT_LPSTR)

       Edit Time: 01:05.47 pm, Mon 01/01/1601 (VT_FILETIME)
    Last printed: (VT_EMPTY)
         Created: 01:42.00 pm, Fri 05/29/1998 (VT_FILETIME)
      Last Saved: 12:31.00 pm, Mon 06/01/1998 (VT_FILETIME)
      Page Count: 1 (VT_I4)
      Word Count: 3 (VT_I4)
      Char Count: 19 (VT_I4)
       Thumpnail: (VT_EMPTY)
         AppName: Microsoft Word 8.0 (VT_LPSTR)
    Doc Security: 0 (VT_I4)
				
==================================================

Thu?c tnh ty ch?nh...

   _PID_LINKBASE: (VT_BLOB)

       _PID_GUID: (VT_BLOB)
       CustProp1: CustProp1TextValue (VT_LPSTR)
       CustProp2: 77777 (VT_I4)
       CustProp3: TRUE/YES (VT_BOOL)
       CustProp4: 00:00.00 am, Tue 05/17/1977 (VT_FILETIME)
				

Thm ghi ch

Cc giao di?n IPropertyStorage v IPropertySetStorage khng ?c xc ?nh trong vi?c pht hnh b?n g?c c?a COM; do m? m?u ny ?i h?i m?t h? th?ng v?i:
  • Windows NT 4.0 ho?c cao hn
  • Windows 95 v?i Internet Explorer phin b?n 4.0 ho?c cao hn
  • Windows 95 v?i DCOM ci ?t
Phin b?n tr?c c?a COM ch? ?nh r?t t ?i v?i thu?c tnh v s? d?ng c?a h?, nhng ? xc ?nh m?t ?nh d?ng ng trn cho php cc nh pht tri?n ? lu tr? cc ti s?n v ti s?n b? trong m?t th? hi?n IStorage. B?t ?ng s?n ?nh danh v ng? ngh?a c?a m?t b? ti s?n duy nh?t, ?c s? d?ng cho b?n tm t?t thng tin v? m?t ti li?u, c?ng ? ?c xc ?nh. T?i th?i i?m , n ? c?n thi?t ? t?o v thao tc c c?u tr?c ti?p nh l m?t d? li?u d?ng. Cho bi?t thm thng tin trn cc thi?t l?p ti s?n xu?t ?nh d?ng d? li?u c c?u t? ch?c, ? c?p ?n "OLE ng trn b?t ?ng s?n Set Format" trong Microsoft Nh pht tri?n m?ng.

(c) t?p on Microsoft 1999, t?t c? cc quy?n. Nh?ng ng gp c?a Joe Crump, Microsoft Corporation.

THAM KH?O

Microsoft Developer Network: Ti s?n lin t?c Sets

Microsoft Developer Network: OLE ng trn b?t ?ng s?n ?t ?nh d?ng

Thu?c tnh

ID c?a bi: 186898 - L?n xem xt sau cng: 20 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Project 2000 Standard Edition
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Excel 97 Standard Edition
  • Microsoft PowerPoint 97 Standard Edition
  • Microsoft Word 97 Standard Edition
  • Microsoft PowerPoint 2000 Standard Edition
  • Microsoft Word 2000 Standard Edition
  • Microsoft Excel 2002 Standard Edition
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft Word 2002 Standard Edition
T? kha:
kbcmpdoc kbfaq kbhowto kbmt KB186898 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:186898

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