CreateProcess crashes

CreateProcess crashes

Post by UkQ » Thu, 20 May 2004 06:51:04


Can't understand why CreateProcessW crashes with memory access violation and CreateProcessA works. Any help is appreciated

#define _WIN32_WINNT 0x050
// Doesn't work begin
#ifndef UNICOD
#define UNICOD
#endif //UNICOD
if(CreateProcess( NULL, L"ipconfig.exe", (LPSECURITY_ATTRIBUTES)NULL
// Doesn't work end

/* Works begin
if(CreateProcess( NULL, "ipconfig.exe", (LPSECURITY_ATTRIBUTES)NULL
// Works ends *

(LPSECURITY_ATTRIBUTES)NULL, FALSE, 0, (LPVOID)NULL, (LPCTSTR)NULL,
(LPSTARTUPINFO) &procStartupInfo, &procInfo) != 0)
 
 
 

CreateProcess crashes

Post by David J. C » Thu, 20 May 2004 07:20:25

Use Visual Studio .NET 2003 and build a simple application that does this.
Change from UNICODE to DBCS and back via the settings menu. Then look at
the output from preprocessor output to see how they differ. My guess is
that UNICODE must be defined before any includes.



and CreateProcessA works. Any help is appreciated.

 
 
 

CreateProcess crashes

Post by Doron Hola » Thu, 20 May 2004 07:31:41

you can't pass a constant string for the W version. from
http://www.yqcomputer.com/

lpCommandLine
[in, out] Pointer to a null-terminated string that specifies the command
line to execute. The maximum length of this string is 32K characters.
Windows 2000: The maximum length of this string is MAX_PATH characters.
The Unicode version of this function, CreateProcessW, will fail if this
parameter is a const string.


d


--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.




and CreateProcessA works. Any help is appreciated.
 
 
 

CreateProcess crashes

Post by UkQ » Thu, 20 May 2004 22:56:04

Thanks for the reply

I didn't correctly state the what fails. Sorry for that. I use VC++ 6.0 and don't have .NET. The "release" version of CreateProcess() works with char* and wchar_t*. It is the "debug" wide char version fails. Debug version of CreateProcessA works fine.
I do compile with UNICDE defined at the top of the file
Dr. Watson shows kernel32!RegisterWaitForInputIdle() as the faulty function when I run the program on the server where no de *** is not installed
 
 
 

CreateProcess crashes

Post by Joe Hage » Fri, 21 May 2004 04:56:28


RD,

Are you initializing the STARTUPINFO structure?
For example:

STARTUPINFO si;

memset(&si, 0, sizeof(si));
si.cb = sizeof(si);


If this structure isn't initialized properly, the code may crash
in NTDLL.


Joe
 
 
 

CreateProcess crashes

Post by Stefan Kuh » Fri, 21 May 2004 06:34:45

Hello RD,



I think you didn't fully understand what Doron wrote to you. This is not
an issue of having VC6 or .NET. Make the memory where the command line
points to writable. Make a copy of the command-line buffer you provide
to CPW on the stack and provide this to CPW and see if the problem goes
away then.


HTH,

--
Stefan
 
 
 

CreateProcess crashes

Post by Doron Hola » Fri, 21 May 2004 17:00:08

correct, instead of this:
CreateProcess( NULL, L"ipconfig.exe", (LPSECURITY_ATTRIBUTES)NULL

where L"ipconfig.exe" is a constant string, do this

func()
{
WCHAR cmdline[] = L"ipconfig.exe";

CreateProcess( NULL, cmdline, (LPSECURITY_ATTRIBUTES)NULL
}

this way the string is not static b/c it stack based.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.





and don't have .NET. The "release" version of CreateProcess() works with
char* and wchar_t*. It is the "debug" wide char version fails. Debug version
of CreateProcessA works fine.
function when I run the program on the server where no de *** is not
installed.