Problem using SHELLEXECUTEEX in VB6 with windows 7 64bits

Hello,

So I've developped a little test to see if I can have a shellexecuteEX waiting for an application. My test works in windows 7 32 bit but not in windows 7 64 bit. I get 0 in hInstApp, and when I look at the following page : SHELLEXECUTEINFO, I can see that the lowest value should be 2. When I launch the test application in win7 32, I get a hInstApp of 42 for my test.
My test is a cmd file named test.cmd and it only contains "pause". this cmd file is launched, and the next line is a msgbox. If the application is waiting, the msgbox won't pop before I press a key to exit the cmd file.
In the win7 64 case, the cmd window doesn't even pop, I only get the msgbox.

Here is my code for the module (mostly coming from somewhere on the web, except the testwait function at the end):
Option Explicit
      Type SHELLEXECUTEINFO
                cbSize As Long
                fMask As Long
                hwnd As Long
                lpVerb As String
                lpFile As String
                lpParameters As String
                lpDirectory As String
                nShow As Long
                hInstApp As Long
                '  Optional fields'
                lpIDList As Long
                lpClass As String
                hkeyClass As Long
                dwHotKey As Long
                hIcon As Long
                hProcess As Long
        End Type
#If VBA7 Then
        Public Declare PtrSafe Function ShellExecuteEx Lib "shell32.dll" (lpExecInfo As SHELLEXECUTEINFO) As Long
        Public Declare PtrSafe Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
        Public Declare PtrSafe Function apiShellExecute 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
        Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
#Else
        Public Declare Function ShellExecuteEx Lib "shell32.dll" (lpExecInfo As SHELLEXECUTEINFO) As Long
        Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
        Public Declare Function apiShellExecute 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
        Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
#End If

        Public Const SEE_MASK_NOCLOSEPROCESS As Long = &H40
        Public Const SEE_MASK_FLAG_DDEWAIT As Long = &H100

        '***App Window Constants***'
        Public Const WIN_NORMAL = 1         'Open Normal'
        Public Const WIN_MAX = 2            'Open Maximized'
        Public Const WIN_MIN = 3            'Open Minimized'

        '***Error Codes***'
        Private Const ERROR_SUCCESS = 32&
        Private Const ERROR_NO_ASSOC = 31&
        Private Const ERROR_OUT_OF_MEM = 0&
        Private Const ERROR_FILE_NOT_FOUND = 2&
        Private Const ERROR_PATH_NOT_FOUND = 3&
        Private Const ERROR_BAD_FORMAT = 11&

Public Enum EShellShowConstants
    essSW_HIDE = 0
    essSW_MAXIMIZE = 3
    essSW_MINIMIZE = 6
    essSW_SHOWMAXIMIZED = 3
    essSW_SHOWMINIMIZED = 2
    essSW_SHOWNORMAL = 1
    essSW_SHOWNOACTIVATE = 4
    essSW_SHOWNA = 8
    essSW_SHOWMINNOACTIVE = 7
    essSW_SHOWDEFAULT = 10
    essSW_RESTORE = 9
    essSW_SHOW = 5
End Enum


' Returns 'True' if file was opened ...'
Public Function fHandleFile(ByVal stFile As String, _
                            ByRef stRet As String, _
                            Optional ByVal lShowHow As EShellShowConstants = essSW_SHOWDEFAULT, _
                            Optional ByVal bWaitForClose As Boolean = False) As Boolean
On Error GoTo err_Handler
    Dim lRet As Long
    Dim ret As Long
    Dim lngProcessHandle As Long
    Dim varTaskID As Variant
    Dim shInfo As SHELLEXECUTEINFO
    Dim retval As Long

    'First try ShellExecute'
    With shInfo
        .cbSize = LenB(shInfo)
        .lpFile = stFile
        .nShow = lShowHow
        If bWaitForClose Then
            .fMask = SEE_MASK_FLAG_DDEWAIT + SEE_MASK_NOCLOSEPROCESS
        End If
        .lpVerb = "open"
    End With

    Call ShellExecuteEx(shInfo)
    lRet = shInfo.hInstApp

    If lRet > ERROR_SUCCESS And bWaitForClose = True Then
        lngProcessHandle = shInfo.hProcess

        Do
            retval = WaitForSingleObject(lngProcessHandle, 0)
            DoEvents
        Loop Until retval <> 258
        ret = CloseHandle(lngProcessHandle)
    End If

    fHandleFile = (lRet > 0)

exit_handler:
    Exit Function

err_Handler:
    MsgBox Err.Number & " from " & Err.Source & " : " & Err.Description
End Function


Public Function testwait() As String
Dim strtmp As String
fHandleFile "c:\factoring\testwait.cmd", strtmp, , True
MsgBox "test ended"
End Function

Open in new window

vanroybelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Don't have a ton of time at the moment, but see if the last comment in this thread, which is an old question that I answered works for you:


http://www.experts-exchange.com/Database/MS_Access/Q_28054927.html#a38973604

Jim.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Also, there are good links in this comment:

http://www.experts-exchange.com/Database/MS_Access/Q_28054927.html#a38966968

 See if the API your using was changed for 64 bit.  

Jim.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vanroybelAuthor Commented:
Thanks, it's not the same question exactly, but it does solve my problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.