Skip to content

Instantly share code, notes, and snippets.

Created Mar 16, 2017
What would you like to do?
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare PtrSafe _
Function IShellFolder_ParseDisplayName Lib "shlwapi.dll" Alias "#317" ( _
ByVal unk As IUnknown, _
ByVal hWnd As LongPtr, _
ByVal pbc As LongPtr, _
ByVal pszDisplayName As LongPtr, _
ByVal pchEaten As Long, _
ByRef ppidl As Long, _
ByVal pdwAttributes As Long) _
As Long
Private Declare PtrSafe _
Function IIDFromString Lib "ole32.dll" ( _
ByVal lpsz As LongPtr, _
ByRef lpiid As GUID _
) As Long
Const IID_IShellFolder = "{000214E6-0000-0000-C000-000000000046}"
Private Declare PtrSafe _
Function SHBindToParent Lib "Shell32.dll" ( _
ByVal pidl As Long, _
ByRef riid As GUID, _
ByRef ppv As IUnknown, _
ByRef ppidlLast As Long) _
As Long
Private Declare PtrSafe _
Function SHGetDesktopFolder Lib "Shell32.dll" ( _
ByRef ppshf As IUnknown) As Long
Private Declare PtrSafe _
Function SHInvokeCommand Lib "shlwapi.dll" Alias "#363" ( _
ByVal hWnd As LongPtr, _
ByVal lpFolder As IUnknown, _
ByVal lpApidl As Long, _
ByRef s As Any) _
As Long
Private Declare PtrSafe Sub ILFree Lib "Shell32.dll" (ByVal pidl As Long)
Const strPath = "フルパス"
Sub hoge()
Dim unk As IUnknown 'IShellFolder
Dim pidl&, hr&
hr = SHGetDesktopFolder(unk)
Dim iid As GUID
hr = IIDFromString(StrPtr(IID_IShellFolder), iid)
hr = IShellFolder_ParseDisplayName(unk, 0, 0, StrPtr(strPath), 0, pidl, 0)
Dim tmp As Long
hr = SHBindToParent(pidl, iid, unk, tmp)
ILFree pidl
Dim B() As Byte
B = "プロパティ(&R)" & vbNullChar
hr = SHInvokeCommand(0, unk, tmp, B(0))
Debug.Print Hex$(hr)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment