Created
March 16, 2017 03:20
-
-
Save kumatti1/4da4b10cf7ff741fbade4bde1f3e8d9e to your computer and use it in GitHub Desktop.
ファイル指定で既定の右クリック呼び出し
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
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 SHInvokeDefaultCommand Lib "shlwapi.dll" Alias "#279" ( _ | |
ByVal hWnd As LongPtr, _ | |
ByVal lpFolder As IUnknown, _ | |
ByVal lpApidl As Long) _ | |
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) | |
Debug.Print Hex$(hr) | |
hr = IShellFolder_ParseDisplayName(unk, 0, 0, StrPtr(strPath), 0, pidl, 0) | |
Debug.Print Hex$(hr) | |
Dim tmp As Long | |
hr = SHBindToParent(pidl, iid, unk, tmp) | |
Debug.Print Hex$(hr) | |
ILFree pidl | |
hr = SHInvokeDefaultCommand(0, unk, tmp) | |
Debug.Print Hex$(hr) | |
ILFree tmp | |
Set unk = Nothing | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment