PRB: Visual C++ 6.0 Compiled Unicode CreateProcess Access ViolationID: Q199290
|
The Unicode version of CreateProcess() attempts to modify the lpCommandLine parameter, causing an access violation when compiled with Visual C++ 6.0 or other compilers that put string literals in read-only memory. For example, the following CreateProcess() command line fails when compiled as Unicode with Visual C++ 6.0:
CreateProcess(NULL,L"Cmd.exe",...)
The ANSI version of CreateProcess() API does not exhibit the problem because internally it makes a read/write Unicode copy of the lpCommandLine parameter, and passes that to CreateProcessW.
The cause of the problem is the default project setting include /ZI flag, which enables Edit and Continue debug information; this flag implies the /GF flag, which enables read-only string pooling.
It is possible to add the /Zi flag to your project options to eliminate the problem. This cancels the read-only access to the string pool, but still allows debug symbols to be generated.
However, a better alternative is to either use the ANSI version of the API, CreateProcessA(), or pass your own read/write buffer with the Unicode command line into CreateProcess(). Because this API does modify the buffer, it is better to remove any confusion by using your own buffer.
This behavior is by design. See the documentation for CreateProcess().
For additional information, please see the following article in the Microsoft Knowledge Base:
Q198477 PRB: Use of /ZI May Cause Access Violation
Additional query words:
Keywords : kbAPI kbKernBase kbSDKPlatform kbSDKWin32 kbVC600
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: May 7, 1999