CreateProcess方法以错误结尾 [英] CreateProcess method ends up with an error

查看:131
本文介绍了CreateProcess方法以错误结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的以下代码有问题:

int main(int argc, char **argv) {
  PROCESS_INFORMATION pi;  
  STARTUPINFO si;     

  printf("Process %d reporting for duty\n",GetCurrentProcessId());
  GetStartupInfo(&si);
  CreateProcess(NULL,"notepad.exe", NULL,NULL,FALSE,DETACHED_PROCESS, NULL,NULL, &si, &pi);
  printf("New Process ID: %d\n",pi.dwProcessId);
  return(0);
}        

在运行时,我在调试时运行它,它在CreateProcess方法上崩溃,并显示以下错误消息:"Tests.exe中0x7c82f29c的未处理异常:0xC0000005:访问冲突写入位置0x00415760. /strong> 这是什么意思?

And on the runing time,I ran this while debuggin and it crashes on the CreateProcess method,with this error message:" Unhandled exception at 0x7c82f29c in Tests.exe: 0xC0000005: Access violation writing location 0x00415760." What does it means???

推荐答案

32位可执行文件的基址始终为0x00400000.根据例外情况,无法写入的地址为0x00415760.这意味着您的代码几乎肯定会尝试写入可执行映像的只读部分.例如,当您尝试写入字符串文字时,就会发生这种情况.

32 bit executables invariably have a base address of 0x00400000. The address that cannot be written to, according to the exception is 0x00415760. Which means that your code is almost certainly trying to write to a read-only part of the executable image. That happens, for example, when you try to write to string literals.

现在,CreateProcess 必须是可修改的内存(它声明为LPTSTR).但是,您正在传递字符串文字.将"notepad.exe"放入可修改的缓冲区中以解决您的问题.

Now, the second parameter to CreateProcess must be modifiable memory (it is declared as LPTSTR). But you are passing a string literal. Put "notepad.exe" in a modifiable buffer to solve your problem.

char CommandLine[] = "notepad.exe";
CreateProcess(NULL, CommandLine, ...

这篇关于CreateProcess方法以错误结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆