>This appears on the face of it to behave similarly to yours
Here's one difference: check performance of both versions in Task Manager ...
>Why do you prefer the code you posted?
I hadn't seen your post when I posted, so it wasn't posted as a preference to that at all. However, the code I posted is the basis of some extensions not (easily) possible with your solution. For example, we can pass parameters to the function to populate our STARTUPINFO variable, which means we can choose where to display our application, what size it's window should be, and all the various windows styles that Shell also supports.
>the cb property in the STARTUPINFO
Microsoft were smart enough to realise that a fair number of their structures might change in size over the years as the API developed (service packs adding features and new operating systems for example). So they provided a member of the structure that tells the OS how big the structure actually is (remember we only pass the pointer to the structure to the API, so there is no other way fore it to know how big the structure being pointed to actually is)
>append bytes to the end as needed to accommodate the strings
Variable length strings are held as pointers in UDTs
>However, if I open multiple instances, the msgboxes wait to fire until all of them are closed
Well, not really. This isn't production code as such, and as it stands isn't designed to be invoked multiple times - and is a great example of the dangers of DoEvents allowing reentrancy in a single-threaded app...
Change the Click_ event to
Code:
[blue]
Private Sub Command1_Click()
Static ClickCount As Long
ClickCount = ClickCount + 1
ExecCmd "c:\windows\notepad.exe"
MsgBox "Click " & ClickCount & vbCrLf & "I only get here when launched program finishes" & vbCrLf & "thus this must be a ShellAndWait ..."
ClickCount = ClickCount - 1
End Sub[/blue]
Then try closing any opened notepads in different orders to get a better picture of what is actually happening.
>"increasingly complex versions"
Well, for example, I have a version that doesn't require DoEvents because I roll my own version that uses MsgWaitForMultipleObjects (which I've illustrated in this forum in the past, so a keyword search should find), which gives me the ability to pick and choose exactly how I want to respond to messages that appear in the queue, whether for the application or globally