Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created March 15, 2017 03:16
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/17d661cd6f928d7874ae7b925da592e6 to your computer and use it in GitHub Desktop.
Save kumatti1/17d661cd6f928d7874ae7b925da592e6 to your computer and use it in GitHub Desktop.
Option Explicit
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)
Private Declare PtrSafe Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As LongPtr, ByVal nFolder As Long, ppidl As Any) As Long
Const CSIDL_PERSONAL = &H5
Sub hoge()
Dim unk As IUnknown 'IShellFolder
Dim pidl&, hr&
SHGetSpecialFolderLocation 0, CSIDL_PERSONAL, pidl
hr = SHGetDesktopFolder(unk)
hr = SHInvokeDefaultCommand(0, unk, pidl)
Debug.Print Hex$(hr)
ILFree pidl
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment