开发者

Problem in CreateProcess function!

开发者 https://www.devze.com 2022-12-22 16:36 出处:网络
I have my main application ,from my main application I will be calling another module(third party) to perform a small operation in my main application,when I call that module..it processes for a parti

I have my main application ,from my main application I will be calling another module(third party) to perform a small operation in my main application,when I call that module..it processes for a particular time 开发者_高级运维say 5 sec.while its proccessing it shows the process in the commmand window with some information..now my main application waits until the called module finishes its process.Now my Question is..how to do I hide this command window without disturbing its process..I tried to use the createprocess but it seems to not work...

for example: my main application is the Parent process and the called application is child process..Parent process should be independent of the child process..check my example below

int main()
{
  execl("c:\\users\\rakesh\\Desktop\\calledapplication.exe","c:\\users\\rakesh\\Desktop    \\calledapplication.exe",0);


}

code in calledapplication
int main
{
  printf("Rakesh");
}

now considering the above if you run the first program...output would appear in the same command window(It shouldnt be like that)...I want the main application to create the process but it should not be affected by child process.


Pass CREATE_NO_WINDOW in the dwCreationFlags parameter of CreateProcess.


You talked about a "command window", so I presume that the child is a console application. In that case you can create the process in a separate conole and optionally force the new console to be iconified or hidden. The following code launch a child process that interprets a batch file (mytest.bat). I hope it can help. Regards.

#include <windows.h>
#include <stdio.h>

int main(int argc, char **argv)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL rv = FALSE;
WCHAR cmdline[] = TEXT("cmd.exe /c mytest.bat");

    memset(&si,0,sizeof(si));
    si.cb = sizeof(si);
// Add this if you want to hide or minimize the console
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE; //or SW_MINIMIZE
///////////////////////////////////////////////////////
    memset(&pi,0,sizeof(pi));
    rv = CreateProcess(NULL, cmdline, NULL, NULL,
                           FALSE, CREATE_NEW_CONSOLE,
                           NULL, NULL, &si, &pi);
    if (rv) {
        WaitForSingleObject(pi.hProcess, INFINITE);
                printf("Done! :)\n");
    }
        else {
                printf("Failed :(\n");

    }

        return rv ? 0 : 1;
}


It sounds like you want the child process's output to show up in a separate window. If so, you want to call CreateProcess and pass it the CREATE_NEW_CONSOLE flag, rather than using exec*.

0

精彩评论

暂无评论...
验证码 换一张
取 消