利用VC控制OFFICE文件(.doc、.xls、.ppt)的摘要属性(标
题、作者、公司 和 备注)
#define WIN32_LEAN_AND_MEAN #define UNICODE
#define _UNICODE #include <iostream>
#include <tchar.h>
#include <ole2.h> int _tmain(int
argc, _TCHAR* argv[]) { TCHAR
szFileName[MAX_PATH]; printf(
"====================================================\\n ");
printf( "Start Demo\\n ");
if(argc
!= 2)
printf( "usage: summinfodemo filename\\n "); else {
_tcscpy(szFileName,argv[1]); _tprintf(_T( "%s\\n "),szFileName); printf(
"====================================================\\n ");
} IStorage *pStorage = NULL;
IPropertySetStorage *pPropSetStg = NULL;
IPropertyStorage *pPropStg = NULL;HRESULT hr;
hr = StgOpenStorageEx(szFileName, STGM_READ | STGM_SHARE_DENY_WRITE, STGFMT_ANY, 0, NULL, NULL,
IID_IPropertySetStorage,
reinterpret_cast <void**> (&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(
"StgOpenStorageEx() failed w/error lx\\n ", hr); return 0; }if(SUCCEEDED(hr)) {
hr = pStorage-> QueryInterface(IID_IPropertySetStorage, (void
**)&pPropSetStg); if(FAILED(hr)) {
printf( "QI
for IPropertySetStorage failed
w/error lx\\n ", hr); pStorage-> Release();
return 0;
}
} if(SUCCEEDED(hr)) {
hr = pPropSetStg-> Open(FMTID_SummaryInformation, STGM_READ |
STGM_SHARE_EXCLUSIVE, &pPropStg); if(FAILED(hr)) {
printf( "No Summary-Information -
w/error lx\\n ",hr); pPropSetStg-> Release();
pStorage-> Release(); return 0; }
}if (SUCCEEDED(hr))