CreateProcessW要注意的细节问题

Home / C++ MrLee 2019-1-23 3460

原先一直用用CreateProcessA没发现什么异常,今天用CreateProcessW发现内存错误。

后来查了下资料,发现其中关于lpCommandLine参数的说明中有一段话。

The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.

大致意思如下:

在unicode版本的CreateProcessW中需要修改字符串的内容。所以,这个参数不能为指向只读内存的指针。如果这个参数是一个常量,函数将产生内存访问错误。

所以用变量拷贝一下就行了。

本文链接:https://www.it72.com/12475.htm

推荐阅读
最新回复 (0)
返回