Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created April 22, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/11197768 to your computer and use it in GitHub Desktop.
Save kumatti1/11197768 to your computer and use it in GitHub Desktop.
pSHStgOpenStorageW
#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));
typedef HRESULT (WINAPI *p_SHStgOpenStorageW)(const WCHAR*,DWORD,DWORD, DWORD, REFIID, void **);
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
{
CoInitialize(NULL);
try {
HMODULE hDll = LoadLibraryW(L"shell32.dll");
if (!hDll) _com_issue_error(S_FALSE);
p_SHStgOpenStorageW pSHStgOpenStorageW = (p_SHStgOpenStorageW)GetProcAddress(hDll, (LPCSTR)683);
IPropertySetStoragePtr pPropSetStg;
HRESULT hr = pSHStgOpenStorageW(FilePath,STGM_READ || STGM_SHARE_DENY_WRITE, 0, 0,IID_PPV_ARGS(&pPropSetStg));
if (FAILED(hr)) _com_issue_error(hr);
}
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