■No33340に返信(ちんぷいさんの記事) > <宣言> > Declare Function WNetConnectionDialog Lib "mpr.dll" _ > (ByVal hwnd As Long, ByVal dwType As Long) As Long > Const RESOURCETYPE_DISK = &H1 > > Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long > > Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
■No33340に返信(ちんぷいさんの記事)
元記事のコードを、動作するように書き換えたモノを貼っておきます。
32bit/64bit 両方で動作確認。
解決済みフラグは付けたままにしておきます。
'---------------
Imports System.ComponentModel
Imports System.Runtime.InteropServices
'---------------
Private Const RESOURCETYPE_DISK As Integer = 1
Private Declare Function WNetConnectionDialog Lib "mpr" (ByVal hWnd As IntPtr, Optional ByVal dwType As Integer = RESOURCETYPE_DISK) As Integer
Private Declare Function GetForegroundWindow Lib "user32" () As IntPtr
Private Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As IntPtr, ByVal lpString As String) As Boolean
'---------------
Dim HWND As IntPtr = GetForegroundWindow()
Dim Ret As Boolean = SetWindowText(HWND, "ABC")
Dim dlg As Integer = WNetConnectionDialog(HWND, RESOURCETYPE_DISK)
If dlg = 0 Then
MsgBox("接続成功!")
ElseIf dlg = -1 Then
MsgBox("キャンセル")
Else
MsgBox("接続失敗:" & CStr(dlg))
End If