获取文件属性详细信息标签下的信息

SuperHeroMario 2018-09-13 05:12:24
有什么方法可以获取文件属性中详细信息标签下的信息呢?例如:
...全文
1240 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuperHeroMario 2018-10-26
  • 打赏
  • 举报
回复
上面的方法都不是很适合,下面是我的代码
QString sdkver;
QString fullName;

LPVOID lpBuffer = NULL;
UINT uLen = 0;
DWORD dwLen = 0;
char* lpData = NULL;
int pos[3] = {0};
int px[3] = {0};
int year,month,day,subday;
int yx,mx,dx,sx;

BOOL bSuccess = FALSE;

//获得文件基础信息
dwLen = GetFileVersionInfoSize(fullName.toStdWString().c_str(), 0);
if(dwLen != 0)
{
lpData = new char [dwLen+1];
bSuccess = GetFileVersionInfo(fullName.toStdWString().c_str(), 0, dwLen, lpData);

//获得语言和代码页(language and code page)
bSuccess = VerQueryValue(lpData,(TEXT("\\VarFileInfo\\Translation")),&lpBuffer,&uLen);

QString strTranslation,str1,str2;
unsigned short int *p = (unsigned short int *)lpBuffer;

str1.setNum(*p,16);
str1="000" + str1;
strTranslation += str1.mid(str1.size()-4,4);

str2.setNum(*(++p),16);
str2="000" + str2;
strTranslation += str2.mid(str2.size()-4,4);

//获得文件版本信息
QString code = "\\StringFileInfo\\"+ strTranslation +"\\FileVersion";
bSuccess = VerQueryValue(lpData,(code.toStdWString().c_str()),&lpBuffer,&uLen);

fileInfo += QString::fromUtf16((const unsigned short int *)lpBuffer);

fileInfo.remove(" ");
fileInfo.replace(",","-");

for(int i = 0,j = 0;i < fileInfo.length(); i ++)
{
if(fileInfo.compare("-",fileInfo.mid(i,1)) == 0)
{
pos[j] = i;
j ++;
}
}

year = fileInfo.mid(0 , pos[0] - 0).toInt(NULL,10);
month = fileInfo.mid(pos[0] + 1, pos[1] - pos[0] - 1).toInt(NULL,10);
day = fileInfo.mid(pos[1] + 1, pos[2] - pos[1] - 1).toInt(NULL,10);
subday = fileInfo.mid(pos[2] + 1, fileInfo.length() - pos[2] - 1).toInt(NULL,10);

delete [] lpData;//此处不需要释放
}
}
赵4老师 2018-09-18
  • 打赏
  • 举报
回复
赵4老师 2018-09-18
  • 打赏
  • 举报
回复
叒供参考:
#pragma comment(lib,"user32")
#include <stdio.h>
#include <string.h>
#include <afxwin.h>
#include <windows.h>
#include <shlwapi.h>
#include "ModulVer.h"
TCHAR szText[MAX_PATH] = TEXT("Could not load DLL");
int v=0;
void GetDllVersion(LPCTSTR lpszDllName) {
HINSTANCE hinstDll;

hinstDll = LoadLibrary(lpszDllName);
if (hinstDll) {
DLLGETVERSIONPROC pDllGetVersion;

/*
You must get this function explicitly because the DLL might not implement
the function. Depending upon the DLL, the lack of implementation of the
function may be a version marker in itself.
*/
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress( hinstDll,TEXT("DllGetVersion"));

if (pDllGetVersion) {
DLLVERSIONINFO dvi;
HRESULT hr;

ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);

hr = (*pDllGetVersion)(&dvi);

if (SUCCEEDED(hr)) {
wsprintf( szText,
TEXT("DLL Version = %d.%02d\nBuild# = %d\n"),
dvi.dwMajorVersion,
dvi.dwMinorVersion,
dvi.dwBuildNumber);

switch(dvi.dwPlatformID) {
case DLLVER_PLATFORM_WINDOWS:
lstrcat(szText, TEXT("Platform is Windows"));
break;

case DLLVER_PLATFORM_NT:
lstrcat(szText, TEXT("Platform is Windows NT"));
break;

default:
lstrcat(szText, TEXT("Platform is not defined"));
break;
}
} else {
lstrcpy( szText,
TEXT("DllGetVersion Failed - Cannot determine DLL version."));
}
} else {
lstrcpy( szText,TEXT("GetProcAddress Failed - The DLL does not implement DllGetVersion."));
}
CString s,vs;
CModuleVersion ver;
CString m_sModuleName(lpszDllName);
if (ver.GetFileVersionInfo(m_sModuleName)) {
vs.Format("%d.%d.%d.%d",
HIWORD(ver.dwFileVersionMS),
LOWORD(ver.dwFileVersionMS),
HIWORD(ver.dwFileVersionLS),
LOWORD(ver.dwFileVersionLS));
s.Format(" Version: %s\n",vs);
static LPCTSTR Keys[] = {
_T("CompanyName"),
_T("FileDescription"),
_T("FileVersion"),
_T("InternalName"),
_T("LegalCopyright"),
_T("OriginalFilename"),
_T("ProductName"),
_T("ProductVersion"),
NULL
};
for (int i=0; Keys[i]; i++) {
CString temp;
temp.Format("%16s: %s\n", Keys[i], ver.GetValue(Keys[i]));
s += temp;
}
if (v) printf("%s\n",vs);
else printf("%s",s);
}
FreeLibrary(hinstDll);
} else {
lstrcpy(szText, TEXT("Could not load the DLL"));
}
if (!v) printf("%s\n",szText);
}
void main(int argc,char **argv) {
if (argc<=1) {
Usage:
printf("Usage: %s [-v] filename.dll\n",argv[0]);
return;
}
if (argc<=2) {
GetDllVersion(argv[1]);
} else {
if (0==stricmp(argv[1],"-v")||0==stricmp(argv[1],"/v")) {
v=1;
GetDllVersion(argv[2]);
} else goto Usage;
}
}
赵4老师 2018-09-18
  • 打赏
  • 举报
回复
再供参考:
#pragma comment(lib,"user32")
#include <stdio.h>
#include <windows.h>
#include <shlwapi.h>
TCHAR szText[MAX_PATH] = TEXT("Could not load DLL");
void GetDllVersion(LPCTSTR lpszDllName) {
HINSTANCE hinstDll;

//Load the DLL.
hinstDll = LoadLibrary(lpszDllName);

if (hinstDll) {
DLLGETVERSIONPROC pDllGetVersion;

/*
You must get this function explicitly because the DLL might not implement
the function. Depending upon the DLL, the lack of implementation of the
function may be a version marker in itself.
*/
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress( hinstDll,TEXT("DllGetVersion"));

if (pDllGetVersion) {
DLLVERSIONINFO dvi;
HRESULT hr;

ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);

hr = (*pDllGetVersion)(&dvi);

if (SUCCEEDED(hr)) {
wsprintf( szText,
TEXT("DLL Version = %d.%02d\nBuild# = %d\n"),
dvi.dwMajorVersion,
dvi.dwMinorVersion,
dvi.dwBuildNumber);

switch(dvi.dwPlatformID) {
case DLLVER_PLATFORM_WINDOWS:
lstrcat(szText, TEXT("Platform is Windows"));
break;

case DLLVER_PLATFORM_NT:
lstrcat(szText, TEXT("Platform is Windows NT"));
break;

default:
lstrcat(szText, TEXT("Platform is not defined"));
break;
}
} else {
lstrcpy( szText,
TEXT("DllGetVersion Failed - Cannot determine DLL version."));
}
} else {
lstrcpy( szText,TEXT("GetProcAddress Failed - The DLL does not implement DllGetVersion."));
}
FreeLibrary(hinstDll);
} else {
lstrcpy(szText, TEXT("Could not load the DLL"));
}
}
void main(int argc,char **argv) {
if (argc<=1) {
printf("Usage: %s filename.dll\n",argv[0]);
return;
}
GetDllVersion(argv[1]);
printf("%s",szText);
}
SuperHeroMario 2018-09-18
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
#pragma comment(lib,"ole32")
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <ole2.h>
#include <locale.h>
void DumpXML(char *xml) {
static char b[8192];
static WCHAR wstr[1024];
char *p,*q;
FILE *f;
int i,L;

f=fopen(xml,"rb");
if (NULL==f) return;
fread(b,1,8192,f);
fclose(f);
printf("================= %s =================\n",xml);
p=b;
for (i=0;i<3;i++) {//跳过前两个标签
p=strchr(p,'<');
if (!p) return;
p++;
}
while (1) {
if ('/'!=p[0]) {
q=strchr(p,'>');
if (!q) return;
printf("%32.*s: ",q-p,p);
p=q+1;
q=strchr(p,'<');
if (!q) return;
L=q-p;
for (i=0;i<L;i++) if ((unsigned char)p[i]>=0x80) break;
if (i<L) {
i=MultiByteToWideChar(CP_UTF8,0,p,L,wstr,1024);
wstr[i] = 0;
printf("%.*s UTF8(%S)\n",L,p,wstr);
} else {
printf("%.*s\n",L,p);
}
p=q+1;
} else {
p=strchr(p,'<');
if (!p) return;
p++;
}
}
}
void TryWinRAR(char *filename) {
char cmd[1080];

if (access("c:\\progra~1\\winrar\\winrar.exe",0)) return;
system("rd /s /q docProps 1>NUL 2>NUL");
sprintf(cmd,"c:\\progra~1\\winrar\\winrar.exe x \"%.1000s\" docProps\\*.xml",filename);
system(cmd);
if (!access("docProps\\core.xml",0)) DumpXML("docProps\\core.xml");
if (!access("docProps\\app.xml",0)) DumpXML("docProps\\app.xml");
system("rd /s /q docProps 1>NUL 2>NUL");
}
void DumpPropVariant(PROPVARIANT *pPropVar) {// Dumps simple PROPVARIANT values.
if (pPropVar->vt & VT_ARRAY) {// Don't iterate arrays, just inform as an array.
printf("%32s%s",""," (Array)\n");
return;
}
if (pPropVar->vt & VT_BYREF) {// Don't handle byref for simplicity, just inform byref.
printf("%32s%s",""," (ByRef)\n");
return;
}
switch(pPropVar->vt) {
case VT_EMPTY:printf("%32s%s",""," (VT_EMPTY)\n" );break;
case VT_NULL :printf("%32s%s",""," (VT_NULL)\n" );break;
case VT_BLOB :printf("%32s%s",""," (VT_BLOB)\n" );break;
case VT_BOOL :printf("%-32s" " (VT_BOOL)\n", pPropVar->boolVal ? "TRUE/YES" : "FALSE/NO");break;
case VT_I2 :printf("%-32d" " (VT_I2)\n" , (int) pPropVar-> iVal );break;
case VT_I4 :printf("%-32d" " (VT_I4)\n" , (int) pPropVar-> lVal );break;
case VT_R4 :printf("%-32.2lf (VT_R4)\n" , (double)pPropVar-> fltVal );break;
case VT_R8 :printf("%-32.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("%-32s (VT_BSTR)\n", dbcs);
}
break;
case VT_LPSTR: // Null-terminated string.
{
char *pbstr = (char *)pPropVar->pszVal;
int i,L;
L=strlen(pbstr);
for (i=0;i<L;i++) if ((unsigned char)pbstr[i]>=0x80) break;
if (i<L) {
WCHAR wstr[1024];
int i = MultiByteToWideChar(CP_UTF8,0,pbstr,-1,wstr,1024);
wstr[i] = 0;
printf("%-32s (VT_LPSTR) UTF8(%S)\n", pPropVar->pszVal,wstr);
} else {
printf("%-32s (VT_LPSTR)\n", pPropVar->pszVal);
}
}
break;
case VT_LPWSTR:
printf("%-32S (VT_LPWSTR)\n", pPropVar->pwszVal);
break;
case VT_FILETIME:
{
FILETIME lft;
FileTimeToLocalFileTime(&pPropVar->filetime, &lft);
SYSTEMTIME lst;
FileTimeToSystemTime(&lft, &lst);

printf("%d-%02d-%02d %02d:%02d.%02d (VT_FILETIME)\n",
lst.wYear, lst.wMonth, lst.wDay,
lst.wHour, lst.wMinute, lst.wSecond);
}
break;
case VT_CF: // Clipboard format.
printf("%32s%s",""," (Clipboard format)\n");
break;
default: // Unhandled type, consult wtypes.h's VARENUM structure.
printf("%32s (Unhandled type: 0x%08lx)\n", "", pPropVar->vt);
break;
}
}
void DumpBuiltInProps(IPropertySetStorage *pPropSetStg) {// Dump's built-in properties of a property storage.
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);
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();

}
void DumpCustomProps(IPropertySetStorage *pPropSetStg) {// Dump's custom properties of a property storage.
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();

}
void DumpProps(char *filename) {// Dump's custom and built-in properties of a compound document.
// 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.\nTry use WinRAR to open docx/xlsx/pptx,view docProps\\core.xml and docProps\\app.xml\n");
if ('.'==filename[strlen(filename)-5]) TryWinRAR(filename);
} 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();
}
void main(int argc, char **argv) {
if (argc != 2) {
printf("OLE/ZIP Document Property Viewer\n");
printf("Usage: %s filename", argv[0]);
return;
}
setlocale( LC_ALL, "chs" );
printf("[File] %s\n",argv[1]);
DumpProps(argv[1]);
}

多谢,一会去试验一下
赵4老师 2018-09-14
  • 打赏
  • 举报
回复
#pragma comment(lib,"ole32")
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <ole2.h>
#include <locale.h>
void DumpXML(char *xml) {
static char b[8192];
static WCHAR wstr[1024];
char *p,*q;
FILE *f;
int i,L;

f=fopen(xml,"rb");
if (NULL==f) return;
fread(b,1,8192,f);
fclose(f);
printf("================= %s =================\n",xml);
p=b;
for (i=0;i<3;i++) {//跳过前两个标签
p=strchr(p,'<');
if (!p) return;
p++;
}
while (1) {
if ('/'!=p[0]) {
q=strchr(p,'>');
if (!q) return;
printf("%32.*s: ",q-p,p);
p=q+1;
q=strchr(p,'<');
if (!q) return;
L=q-p;
for (i=0;i<L;i++) if ((unsigned char)p[i]>=0x80) break;
if (i<L) {
i=MultiByteToWideChar(CP_UTF8,0,p,L,wstr,1024);
wstr[i] = 0;
printf("%.*s UTF8(%S)\n",L,p,wstr);
} else {
printf("%.*s\n",L,p);
}
p=q+1;
} else {
p=strchr(p,'<');
if (!p) return;
p++;
}
}
}
void TryWinRAR(char *filename) {
char cmd[1080];

if (access("c:\\progra~1\\winrar\\winrar.exe",0)) return;
system("rd /s /q docProps 1>NUL 2>NUL");
sprintf(cmd,"c:\\progra~1\\winrar\\winrar.exe x \"%.1000s\" docProps\\*.xml",filename);
system(cmd);
if (!access("docProps\\core.xml",0)) DumpXML("docProps\\core.xml");
if (!access("docProps\\app.xml",0)) DumpXML("docProps\\app.xml");
system("rd /s /q docProps 1>NUL 2>NUL");
}
void DumpPropVariant(PROPVARIANT *pPropVar) {// Dumps simple PROPVARIANT values.
if (pPropVar->vt & VT_ARRAY) {// Don't iterate arrays, just inform as an array.
printf("%32s%s",""," (Array)\n");
return;
}
if (pPropVar->vt & VT_BYREF) {// Don't handle byref for simplicity, just inform byref.
printf("%32s%s",""," (ByRef)\n");
return;
}
switch(pPropVar->vt) {
case VT_EMPTY:printf("%32s%s",""," (VT_EMPTY)\n" );break;
case VT_NULL :printf("%32s%s",""," (VT_NULL)\n" );break;
case VT_BLOB :printf("%32s%s",""," (VT_BLOB)\n" );break;
case VT_BOOL :printf("%-32s" " (VT_BOOL)\n", pPropVar->boolVal ? "TRUE/YES" : "FALSE/NO");break;
case VT_I2 :printf("%-32d" " (VT_I2)\n" , (int) pPropVar-> iVal );break;
case VT_I4 :printf("%-32d" " (VT_I4)\n" , (int) pPropVar-> lVal );break;
case VT_R4 :printf("%-32.2lf (VT_R4)\n" , (double)pPropVar-> fltVal );break;
case VT_R8 :printf("%-32.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("%-32s (VT_BSTR)\n", dbcs);
}
break;
case VT_LPSTR: // Null-terminated string.
{
char *pbstr = (char *)pPropVar->pszVal;
int i,L;
L=strlen(pbstr);
for (i=0;i<L;i++) if ((unsigned char)pbstr[i]>=0x80) break;
if (i<L) {
WCHAR wstr[1024];
int i = MultiByteToWideChar(CP_UTF8,0,pbstr,-1,wstr,1024);
wstr[i] = 0;
printf("%-32s (VT_LPSTR) UTF8(%S)\n", pPropVar->pszVal,wstr);
} else {
printf("%-32s (VT_LPSTR)\n", pPropVar->pszVal);
}
}
break;
case VT_LPWSTR:
printf("%-32S (VT_LPWSTR)\n", pPropVar->pwszVal);
break;
case VT_FILETIME:
{
FILETIME lft;
FileTimeToLocalFileTime(&pPropVar->filetime, &lft);
SYSTEMTIME lst;
FileTimeToSystemTime(&lft, &lst);

printf("%d-%02d-%02d %02d:%02d.%02d (VT_FILETIME)\n",
lst.wYear, lst.wMonth, lst.wDay,
lst.wHour, lst.wMinute, lst.wSecond);
}
break;
case VT_CF: // Clipboard format.
printf("%32s%s",""," (Clipboard format)\n");
break;
default: // Unhandled type, consult wtypes.h's VARENUM structure.
printf("%32s (Unhandled type: 0x%08lx)\n", "", pPropVar->vt);
break;
}
}
void DumpBuiltInProps(IPropertySetStorage *pPropSetStg) {// Dump's built-in properties of a property storage.
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);
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();

}
void DumpCustomProps(IPropertySetStorage *pPropSetStg) {// Dump's custom properties of a property storage.
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();

}
void DumpProps(char *filename) {// Dump's custom and built-in properties of a compound document.
// 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.\nTry use WinRAR to open docx/xlsx/pptx,view docProps\\core.xml and docProps\\app.xml\n");
if ('.'==filename[strlen(filename)-5]) TryWinRAR(filename);
} 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();
}
void main(int argc, char **argv) {
if (argc != 2) {
printf("OLE/ZIP Document Property Viewer\n");
printf("Usage: %s filename", argv[0]);
return;
}
setlocale( LC_ALL, "chs" );
printf("[File] %s\n",argv[1]);
DumpProps(argv[1]);
}

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧