Created
April 21, 2014 23:04
-
-
Save kumatti1/11159532 to your computer and use it in GitHub Desktop.
XPでIPropertyStore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define Microsoft_Office_Metadata_Handler L"{993BE281-6695-4BA5-8A2A-7AACBFAAB69E}" | |
#define Microsoft_Office_Thumbnail_Handler L"{C41662BB-1FA0-4CE0-8DC5-9B7F8279FF97}" | |
#define FilePath L"実際のパス" | |
#include <windows.h> | |
#include <ObjIdl.h> | |
#include <Propsys.h> | |
#include <Shlwapi.h> | |
#include <comdef.h> | |
#include <Propvarutil.h> | |
_COM_SMARTPTR_TYPEDEF(IPersistFile, __uuidof(IPersistFile)); | |
_COM_SMARTPTR_TYPEDEF(IPropertySetStorage, __uuidof(IPropertySetStorage)); | |
_COM_SMARTPTR_TYPEDEF(IPropertyStore, __uuidof(IPropertyStore)); | |
int CALLBACK WinMain( | |
_In_ HINSTANCE hInstance, | |
_In_ HINSTANCE hPrevInstance, | |
_In_ LPSTR lpCmdLine, | |
_In_ int nCmdShow | |
) | |
{ | |
CoInitialize(NULL); | |
try { | |
CLSID clsid; | |
HRESULT hr = CLSIDFromString(Microsoft_Office_Metadata_Handler, &clsid); | |
if (FAILED(hr)) _com_issue_error(hr); | |
IUnknownPtr pUnk; | |
hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pUnk)); | |
if (FAILED(hr)) _com_issue_error(hr); | |
IPersistFilePtr pPersist; | |
hr = pUnk.QueryInterface(IID_PPV_ARGS(&pPersist)); | |
hr = pPersist->Load(FilePath, STGM_READ); | |
IPropertySetStoragePtr pPropSetStg; | |
hr = pUnk.QueryInterface(IID_PPV_ARGS(&pPropSetStg)); | |
if (FAILED(hr)) _com_issue_error(hr); | |
IPropertyStorePtr pPropStore; | |
hr = ::PSCreatePropertyStoreFromPropertySetStorage(pPropSetStg, STGM_READWRITE, IID_PPV_ARGS(&pPropStore)); | |
if (FAILED(hr)) _com_issue_error(hr); | |
PROPERTYKEY propKey = { FMTID_SummaryInformation, PIDSI_COMMENTS }; | |
PROPVARIANT propValue = { 0 }; | |
hr = pPropStore->GetValue(propKey, &propValue); | |
if (FAILED(hr)) _com_issue_error(hr); | |
PWSTR pstr; | |
hr = PropVariantToStringAlloc(propValue, &pstr); | |
if (FAILED(hr)) _com_issue_error(hr); | |
MessageBoxW(nullptr, pstr, L"value", MB_OK); | |
CoTaskMemFree(pstr); | |
::PropVariantClear(&propValue); | |
} | |
catch (_com_error& e) { | |
MessageBoxA(nullptr, (LPCSTR) e.ErrorMessage(), "err", MB_OK); | |
} | |
CoUninitialize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment