CreateProcess() fails with an access violation [duplicate]

The second argument is a LPTSTR, namely a pointer to a non-const char array. The docs specifically say:

this parameter cannot be a pointer to read-only memory (such as a
const variable or a literal string)

The reason passing a string literal is a problem:

The system adds a terminating null character to the command-line
string to separate the file name from the arguments. This divides the
original string into two strings for internal processing.

Which means in your case, it tries to modify read-only memory, hence the crash.

Leave a Comment