Solved

CreateProcess fails with GetLastError=0

Posted on 1997-09-03
5
1,320 Views
Last Modified: 2013-12-03
hi,

I call CreateProcess with the lpEnvironment parameter pointing to a buffer containing a lot of environment variables (see below) and the result is FALSE, with GetLastError = 0.
Then I recall CreateProcess, but with lpEnvironment = NULL, and I get the same results.

As the Winexec or ShellExececute functions returns 0 if the OS is out of memory or resources, I tried to reboot my machine (even if I run NT !!), but the CreateProcess behaviour keeps the same.

What's happening? Any comments or suggestions welcome.

laurent

my buffer format for the lpEnvironment: 'envVar1=value1§envVar2=value2§...envVarX=valueX§§', where the §§ stands for a zero byte)
0
Comment
Question by:poupou
5 Comments
 
LVL 4

Expert Comment

by:md041797
Comment Utility
Post the code for the call.
0
 
LVL 2

Expert Comment

by:alexxx
Comment Utility
Is it possible that there is some other API call (successful) got inbetween CreateProcess() and GetLastError()?
0
 
LVL 1

Expert Comment

by:ksato
Comment Utility
Seeing that you get the same strange results with the environment parameter set to NULL or not, this is the CreateProcess I use that works.  Try it out to make sure your system is behaving properly, as it is quite simple.  And then from there you can narrow down what is going wrong.

   // process initialization information
   startUpInfo.cb = sizeof(STARTUPINFO);
   startUpInfo.lpReserved = NULL;
   startUpInfo.lpDesktop = NULL;
   startUpInfo.lpTitle = NULL;
   startUpInfo.dwFlags = NULL;
   startUpInfo.cbReserved2 = 0;
   startUpInfo.lpReserved2 = NULL;
   startUpInfo.wShowWindow = SW_SHOWDEFAULT;


if (!(CreateProcess(NULL,
                    commandString,
                    NULL,
                    NULL,
                    FALSE,
                    CREATE_NEW_CONSOLE,
                    NULL,
                    NULL,
                   &startUpInfo,
                    &procInfo)))
{
   cout << "Error creating process" << endl;
   dwErrorCode = GetLastError();
   return -1;
}


0
 

Expert Comment

by:mattyg102096
Comment Utility
To make sure that you are getting the right response from GetLastError(), I'd switch the two lines around.  Make the call to GetLastError() before your 'cout' line.  Who knows what the implementation of cout is calling.  Since this is a console app(?), it would undoubtedly call some of the Console APIs.  These APIs (which are successful) would zero out the GetLastError() code for the thread.

So, call GetLastError first, and then print your message.  Even better, make the error code part of the error message:

cout << "Error creating process.  GetLastError() == " << dwErrorCode << endl;
0
 
LVL 3

Accepted Solution

by:
vinniew earned 50 total points
Comment Utility
You may have to make a call to AllocConsole before running it like that.


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now