S
SS
I am launching the browser from Menu Item that is added to Menu bar in
Microsoft Project using COM ADD IN. I am trying to call the browser in two
ways
1. Using shell command directly passing url to the explore.exe
Here the browser gets opened properly but control is not returned back
to MSP and I have to close the MSP forcibly as it's not responding
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
2. Using win32 API to call default browser and then passing URL to it.
The browser is not opened at all and it gives error code 2 (which is
for URL length greater than 256)
I searched on MSDN and come to know that this problem is for 16-bit not
for 32-bit then why I am still getting this error?
Private Const SW_NORMAL = 5
Public 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
Public Sub OpenBrowser(ByVal URL As String)
Dim APIReturnCode As Long
MsgBox "The URL to be opened!" & URL
APIReturnCode = apiShellExecute(hwnd, "Open", URL, _
vbNullString, app.Path, vbNormalFocus)
If APIReturnCode < 31 Then
MsgBox "Problem running your web browser. You should check that your browser
is correctly installed. (Error " & Format$(APIReturnCode) & ")", 48,
"Browser Unavailable"
ElseIf APIReturnCode = 32 Then
MsgBox app.Title & " could not find a file association for " & URL & " on
your system. You should check that your browser is correctly installed and
associated with this type of file.", 48, "Browser Unavailable"
End If
End Sub
Please help me out on this issue!
Microsoft Project using COM ADD IN. I am trying to call the browser in two
ways
1. Using shell command directly passing url to the explore.exe
Here the browser gets opened properly but control is not returned back
to MSP and I have to close the MSP forcibly as it's not responding
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
2. Using win32 API to call default browser and then passing URL to it.
The browser is not opened at all and it gives error code 2 (which is
for URL length greater than 256)
I searched on MSDN and come to know that this problem is for 16-bit not
for 32-bit then why I am still getting this error?
Private Const SW_NORMAL = 5
Public 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
Public Sub OpenBrowser(ByVal URL As String)
Dim APIReturnCode As Long
MsgBox "The URL to be opened!" & URL
APIReturnCode = apiShellExecute(hwnd, "Open", URL, _
vbNullString, app.Path, vbNormalFocus)
If APIReturnCode < 31 Then
MsgBox "Problem running your web browser. You should check that your browser
is correctly installed. (Error " & Format$(APIReturnCode) & ")", 48,
"Browser Unavailable"
ElseIf APIReturnCode = 32 Then
MsgBox app.Title & " could not find a file association for " & URL & " on
your system. You should check that your browser is correctly installed and
associated with this type of file.", 48, "Browser Unavailable"
End If
End Sub
Please help me out on this issue!