?
Solved

CreateProcess fails with GetLastError=0

Posted on 1997-09-03
5
Medium Priority
?
1,465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 total points
ID: 1405567
You may have to make a call to AllocConsole before running it like that.


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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.  …
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

800 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