I am trying to call a C++ program for a Windows Forms App and to subsequently wait until the exe finishes. So far here is what I have:
Dim ProcessID As Integer Dim ProcessHandle As Integer ProcessID = Shell(filepath_exe, AppWinStyle.NormalFocus) ' Check the Shell command worked If ProcessID <> 0 Then ' Get a process handle for the PID ProcessHandle = OpenProcess(SYNCHRONIZE, 0, ProcessID) ' Wait for the program to finish using the process handle If ProcessHandle <> 0 Then If WaitForSingleObject(ProcessHandle, INFINITE) = WAIT_OBJECT_0 Then ShellandWait = True Else ShellandWait = False End If Else ' Failed to get process handle therefore flag error ShellandWait = False End If Else ShellandWait = False End If
When I run this, the exe executes correctly but the 'waiting part' of this function is not working. Specifically, the following error message appears after the exe has opened (corresponding to line 9 of the code above):
Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'F:\...\Debug\PCA2011_GUI.vshost.exe'.
Additional Information: A call to PInvoke function 'PCA2011_GUI!PCA2011_GUI.GUI::OpenProcess' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
PS I am using Visual Studio to compile and debug this program