Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Option Explicit
Declare Sub CoTaskMemFree Lib “Ole32.dll” (ByVal pv&)
Declare Function lstrlenW& Lib “Kernel32.dll” (ByVal lpString&)
Declare Sub RtlMoveMemory Lib “Kernel32.dll” (ByVal Destination&, ByVal Source&, ByVal length&)
Sub hoge()
Dim o As IFileOpenDialog
Dim si As IShellItem
Dim tmp&, hr&, length&, s$
Set o = New FileOpenDialog
hr = o.Show(Application.Hwnd)
’ 非選択時
If hr < 0 Then Exit Sub
’ IShellItemの参照のセット
Set si = o.GetResult
’ 選択したパスを得る
si.GetDisplayName SIGDN_FILESYSPATH, VarPtr(tmp)
length = lstrlenW(tmp)
s = String$(length, 0)
RtlMoveMemory StrPtr(s), tmp, length * 2
CoTaskMemFree tmp
MsgBox s
End Sub
# アップローダーに置きました。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment