Hi friends,
I am working with vc++.Net...In my project, the first module is that i have to spawn an exe application(Say Ex:Notepad)...I used create process to spawn the Notepad application...Also i have one ini file which is used in my Project and an external dll created using C# code...In my project If i cant spawn the Notepad application due to any situation then i ll display a messsage "Cannot spawn the Child process".. My problem is : i have to create exe for this project in release mode...If i select "Release" mode from the IDE and run the application it works perfectly [After doing some changes in settings 1.Project Menu--->Property pages---> C/C++ --->General---> Debug Information Format , in changed to Program Database
2.)Property pages---> C/C++ ---Optimization---Optimization, i select disabled.]
after i did this changes application runs successfully and spawn the notepad application in both "Debug" and "Release" Modes...

After running this i go to the release folder and try to run the exe file created there [by double clicking]...But i got the message "Cannot spawn the Child process".."Why??? Any known friends Help me...Thanks in advance...Sherin

Recommended Answers

All 12 Replies

In the program, did you give CreateProcess() the full path to the file? e.g. c:\windows\system32\notepad.exe? If not, then I suspect the problem may be in the environment variables. The system was probably looking for notepad.exe and couldn't find it. You can easly test this by adding the full path, recompile then retest.

Hi thanks for responding me and i just check as u told...if i select the "Release Mode" from IDE then i Compile and run the application then it works fine..But if i run the application with the exe (Clicking the exe)which i got from release folder,i got the user defined message "Cannot spawn the Child process"...The following is the code which i have used for creating a process...

CreateProcess( NULL , "C:\\windows\\notepad.exe", NULL, NULL, FALSE, 0 , NULL, NULL, &stInfo , &pi);
Kindly help me ...Sherin

works ok for me (VC++ 2008 Express). The only thing I did with configuration was to turn off UNICODE. Otherwise this is just a normal console program.

#include <windows.h>
#include<iostream>
using namespace std;

int main()
{
STARTUPINFO stInfo;
PROCESS_INFORMATION pi;
memset(&stInfo,0,sizeof(stInfo));
stInfo.cb = sizeof(stInfo);

   BOOL b = CreateProcess( NULL , "C:\\windows\\notepad.exe", NULL, NULL, FALSE, 0 , NULL, NULL, &stInfo , &pi);
   if(b)
       cout << "All ok\n";
   else
       cout << "Failed to create process\n";

}

Hi thanks for responding me and i just check as u told...if i select the "Release Mode" from IDE then i Compile and run the application then it works fine..But if i run the application with the exe (Clicking the exe)which i got from release folder,i got the user defined message "Cannot spawn the Child process"...The following is the code which i have used for creating a process...

CreateProcess( NULL , "C:\\windows\\notepad.exe", NULL, NULL, FALSE, 0 , NULL, NULL, &stInfo , &pi);
Kindly help me ...Sherin

When CreateProcess() fails, call GetLastError() to get the reason for the failure.

hi thanks for responding me...GetLastError returns 0...and i am working with vc++.Net...And How to turnoff the unicode code...Where is that option present...Thanks in advance...Kindly help me...

BOOL bSpawned = FALSE;
STARTUPINFO stInfo;

PROCESS_INFORMATION pi;

bSpawned = CreateProcess( NULL , (LPSTR)APPFileName, NULL, NULL, FALSE, 0 , NULL, NULL, &stInfo , &pi);

//bSpawned = CreateProcess( NULL , "C:\\windows\\notepad.exe", NULL, NULL, FALSE, 0 , NULL, NULL, &stInfo , &pi);

DWORD dwerr = GetLastError();

gProcessID = pi.dwProcessId;
gProcessHandle = pi.hProcess;

return bSpawned;
}

>>And How to turnoff the unicode code...
In VC++ 2008 Express -- Project --> Properties -->Configuration Properties-->General
In the right pane, change Character Set to Not Set

See the code I posted -- you did not initialize stInfo structure.

HI friend, i did as u told...But it didnt work still...I could run the application successfully in release mode[From IDE].... When i run this i got a release folder there i got one exe...If i try to run that by double clicking that i am getting message..."Could not spawn the child process" ...i turn off the unicode still it doesnt work...kindly help me...What could be the reason..
how to initialize this...
STARTUPINFO stInfo;
Need i initialize all the variables which i am using in this application...sherin

hi...the Notepad application gets launched only if i keep

"DWORD dwerr = GetLastError();" this line in the above code which i had given already...Otherwise i got error "Could not launch child process"...when runing the application from the IDE with releaseMode option...kindly help me...sherin

how to initialize this...
STARTUPINFO stInfo;

At minimum, you need to initialize the STARTUPINFO structure's cb member.

PROCESS_INFORMATION pi = {0};
STARTUPINFO stInfo = {0};
// set the size of the struct
stInfo.cb = sizeof(stInfo);

PS. Please use code tags when you post code.

Dear friend thank u tooooooooooooooooooooooooooooooooo much for ur help my application is running after initializing "stInfo"... Thanks for ur help..

Dear friend thank u tooooooooooooooooooooooooooooooooo much for ur help my application is running after initializing "stInfo"... Thanks for ur help..Many people get good names becoz of helping heart like u...Take care...

Dear friend thank u tooooooooooooooooooooooooooooooooo much for ur help my application is running after initializing "stInfo"... Thanks for ur help..Many people get good names becoz of helping heart like u...Take care...

Yea, I told you to do that a day ago :) People often waste hours or days because of failure to read and comprehend what they read. That was your problem here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.