修改
对于VB 6
结束编辑
嘿,这似乎应该是一个简单的修复,我不是特别喜欢Visual Basic语言,但是如何使用代码在默认Web浏览器中打开URL?
修改
为什么我一直收到这个错误?
调用PInvoke函数'CrackleMail!WindowsApplication1.FormFinal :: ShellExecute' 堆栈不平衡。这很可能是因为托管的PInvoke签名与 非托管目标签名。检查PInvoke的调用约定和参数 签名匹配目标非托管签名。
答案 0 :(得分:12)
接受的答案中的代码给我一个编译错误 我从MSDN Use ShellExecute to launch the default Web browser
获得了以下代码Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA"( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
Private Sub Command1_Click()
Dim r As Long
r = ShellExecute(0, "open", "http://www.microsoft.com", 0, 0, 1)
End Sub
答案 1 :(得分:11)
VB.NET:
System.Diagnostics.Process.Start("http://example.com")
VB 6(不确定):
Declare Function ShellExecuteA Lib "shell32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Integer) As IntPtr
ShellExecuteA(Me.Handle, "open", "http://example.com", "", "", 4)
答案 2 :(得分:3)
很简单!
只需使用Wscript createobject
方法
CreateObject("Wscript.Shell").Run "www.example.com"
答案 3 :(得分:0)
Option Explicit
'Link the kernel method that allows a process to be open/spawn
Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
Private Sub mnuAbrirNavegador_Click(Index As Integer)
OpenUrl("http://www.microsoft.com")
End Sub
Private Sub OpenUrl(ByVal url As String)
r = ShellExecute(0, "open", url, 0, 0, 1)
End Sub