Translate

ebook【Delphi跨平台資料庫程式設計火速上手】電子書出版 (CHT)

Delphi 跨平台資料庫程式設計火速上手,是本關於整合 Delphi 的跨平台技術打造 2-Tier 架構的跨平台 APP 的入門技術書。 全書沒有需要理解的技術知識,只講套路。 力求短時間把製作 APP 的工法熟悉,未來要開發其它的應用程式也能舉一反三。 底下...

2013/06/10

EAccessViolation in function CreateProcess in Delphi 2009

很有趣的,我也遇到了這件事情,明明 CreateProcess 這函式在Delphi 7時就正常,到了Delphi 2009就出怪手了。

原因就是出在Unicode……解法轉貼如下:

The problem is in the lpCommandLine parameter. I suspect you are doing something like this:
var
  CmdLine: string;
...
CmdLine := 'notepad.exe';
CreateProcess(nil, PChar(CmdLine), ...)


This results in an access violation because CmdLine is not writeable memory. The string is a constant string stored in read-only memory.

Instead you can do this:
CmdLine := 'notepad.exe';
UniqueString(CmdLine);
CreateProcess(nil, PChar(CmdLine), ...)

This is enough to make CmdLine be backed by writeable memory.

It is not enough just to make the variable holding the string non-const, you need to make the memory that backs the string writeable too. When you assign a string literal to a string variable, the string variable points at read-only memory.

參考來源:Access Violation in function CreateProcess in Delphi 2009

沒有留言:

張貼留言