长沙三甲医院大胸缩小:利用VC控制OFFICE文件(.doc、.xls、.ppt)的摘要属性(标题、作者、公司 和 备注)

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 21:59:37
#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   %08lx\n ",   hr);
return   0;
}

if(SUCCEEDED(hr))
{
hr   =   pStorage-> QueryInterface(IID_IPropertySetStorage,   (void
**)&pPropSetStg);
if(FAILED(hr))
{
printf( "QI   for   IPropertySetStorage   failed   w/error   %08lx\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   %08lx\n ",hr);
pPropSetStg-> Release();
pStorage-> Release();
return   0;
}
}

if   (SUCCEEDED(hr))
{
struct   pidsiStruct
{
char   *name;
long   pidsi;
}
pidsiArr[]   =
{
{ "Title ",   PIDSI_TITLE},   //   VT_LPSTR
{ "Subject ",   PIDSI_SUBJECT},   //   ...
{ "Author ",   PIDSI_AUTHOR},
{ "Keywords ",   PIDSI_KEYWORDS},
{ "Comments ",   PIDSI_COMMENTS},
{0,   0}
};
int   nPidsi   =   0;
for(nPidsi=0;   pidsiArr[nPidsi].name;   nPidsi++);
        PROPSPEC   *pPropSpec   =   new   PROPSPEC   [nPidsi];
        PROPVARIANT   *pPropVar   =   new   PROPVARIANT   [nPidsi];
for(int   i=0;   i <nPidsi;   i++)
{
ZeroMemory(&pPropSpec,   sizeof(PROPSPEC));
pPropSpec.ulKind   =   PRSPEC_PROPID;
pPropSpec.propid   =   pidsiArr.pidsi;
}

hr   =   pPropStg-> ReadMultiple(nPidsi,   pPropSpec,   pPropVar);
if   (SUCCEEDED(hr))
{
for(int   i=0;   i <nPidsi;   i++)
{
_TCHAR   sValue[1024]   =   {0};
std::string   strTemp   =   pPropVar-> pszVal;
printf( "\t%s\n ",strTemp.c_str());
pPropVar++;
}
}
}

pPropSetStg-> Release();
pPropStg-> Release();
pStorage-> Release();
printf( "===================================================\n ");
printf( "End   Demo\n ");


return   0;