PRB: Visual C++ 6.0 Compiled Unicode CreateProcess Access Violation

ID: Q199290


The information in this article applies to:


SYMPTOMS

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.


CAUSE

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.


RESOLUTION

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.


STATUS

This behavior is by design. See the documentation for CreateProcess().


REFERENCES

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