Created
April 22, 2014 23:22
-
-
Save kumatti1/11197768 to your computer and use it in GitHub Desktop.
pSHStgOpenStorageW
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 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