Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateProcess method ends up with an error

I've a problem with my following code:

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);
}        

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???

like image 550
Inbali Avatar asked Feb 06 '12 22:02

Inbali


1 Answers

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.

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, ...
like image 152
David Heffernan Avatar answered Sep 19 '22 00:09

David Heffernan