I use ShellExecute to launch an application from VB6. I then use FindWindow to get the application's window handle. Using Spy++ I know the class and the window caption, which I input into the FindWindow call.
What happens is that FindWindow returns 0 and no window caption BUT, if I start a new instance of the application (by clicking on a launch button whose click procedure does the ShellExecute), then FindWindow returns a handle of the first instance. This is very reproducible but certainly not what I am after.
Below is the code I have in my command click procedure:

Private Sub Command1_Click()
Dim r As Long 'Variable to store the response string
Dim buffer As String
Dim numChars As Integer
Dim hwndPHD As Long

r = ShellExecute(0, "Open", "C:\Program Files\PHDGuiding\PHD.exe", 0, 0, SW_SHOWNORM)
lbltask_ID.Caption = Hex$(r)
hwndPHD = FindWindow("wxWindowClassNR", "PHD Guiding 1.10.0 - www.stark-labs.com (Log active)")

'Debug.Print Hex$(hwndPHD)
If hwndPHD <> 0 Then
' Init buffer
buffer = Space$(128)
' Get caption of window
numChars = GetWindowText(hwndPHD, buffer, Len(buffer))
lblhWnd.Caption = Hex$(hwndPHD)
' Display window's caption
lblWinCaption.Caption = Left$(buffer, numChars)
End If
End Sub


All the API declarations are done in a control module and I get no error when running the application in the IDE.
I do not understand what is going on and will welcome any insight
Thanks
Olivier