When is control given back to calling program?

Hi.

I encounter a problem with the following DLL :

#include <windows.h>
#include <string>

using namespace std;

void __stdcall MYFUNCTION(long anynumber)

{

SHELLEXECUTEINFOA command1;
ZeroMemory (&command1, sizeof (SHELLEXECUTEINFOA));
command1.cbSize = sizeof (SHELLEXECUTEINFOA);
command1.lpVerb = "open";
command1.lpFile = string1;
command1.lpParameters = string2;
command1.nShow = SW_HIDE;
command1.fMask = SEE_MASK_NOCLOSEPROCESS;
ShellExecuteExA(&command1);
WaitForSingleObject(command1.hProcess, INFINITE);

}

This DLL calls a program (MyProgram.exe) whose full path name is provided in 'string1'. MyProgram reads a file whose full path name is provided in 'string2' and creates a file whose name is also provided in 'string2'.
The output file is further exploited in the program calling the DLL.

Everything works fine but based on the results found after exploitation of the output file, I see that there is some delay in the values provided by the DLL.
I have got the feeling that the DLL gives control back to the calling program before MyProgram.exe is finished (or when the output file is not yet closed).

So my question is : does this DLL executes 'synchronously'? Stated otherwise, is control given back to the DLL (and thus also to the program calling this DLL) only after MyProgram.exe is finished? If not, what should be changed in order to have the DLL not give control back to the calling program before MyProgram.exe is finished?

Thanks in advance for your help.
I see that there is some delay in the values provided by the DLL.
not quite sure what you mean.

I have got the feeling that the DLL gives control back to the calling program before MyProgram.exe is finished (or when the output file is not yet closed).
It doesn't.

does this DLL executes 'synchronously'?
The function returns when the process terminates (or doesn't start because of an error).

You need to close the process and thread handles. You don't.
Hi kbw.

Thanks for your comments.

Indeed I should not have used the term 'delay'. This DLL is used on a trading platform. It is called in each minute interval. What I found is that when the DLL is called let's say in interval n, the output file created by the exe called by the DLL
seems to only be made available in interval n+1.

I am not an expert in C++. The code shown is just a rework of a piece of code I found on the internet.

Can you tell me how the DLL should be modified in order to close the process and the thread?

Thanks in advance.
Years ago, I worked at a bank that rolled started using Daytona Gold, later to be officially released as NT 3.5. There was a process that would fall over regularly, something like every seven days. It was traced to the process using cmd.exe to run a program. It didn't close those handles and eventually ran out.

Use CloseHandle(command1.hProcess); to close the process handle. I hope ShellExecuteEx closes the thread handle for you, because SHELLEXECUTEINFO doesn't appear to provide the thread handle to you. CreateProcess gives you that stuff.

With closed source software, you can never be sure what it's doing.
Topic archived. No new replies allowed.