Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CreateProcess fails with GetLastError=0

Posted on 1997-09-03
5
Medium Priority
?
1,526 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

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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