Solved

CreateProcess fails with GetLastError=0

Posted on 1997-09-03
5
1,364 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
ID: 1405563
Post the code for the call.
0
 
LVL 2

Expert Comment

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

Expert Comment

by:ksato
ID: 1405565
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
ID: 1405566
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
ID: 1405567
You may have to make a call to AllocConsole before running it like that.


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 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