If you look at the MSDN documentation of CreateProcess you might notice the following remark for the lpCommandLine parameter:

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.

This means that when you move over to Unicode (Delphi 2009/2010) existing code might produce an Access Violation.

This code for example will produce an Access Violation:

CreateProcess(nil, ‘notepad.exe’, nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo);

To prevent these kinds of Access Violation we could change the declaration of the lpCommandLine parameter as var. This prevents passing nil though (which is allowed).

So if we want to allow passing nil but not a constant we should declare 2 overloaded functions:

function CreateProcessW(
  lpApplicationName: LPCWSTR;
  var lpCommandLine: LPWSTR;
  lpProcessAttributes, lpThreadAttributes: LPSECURITY_ATTRIBUTES;
  bInheritHandles: BOOL;
  dwCreationFlags: DWORD;
  lpEnvironment: LPVOID;
  lpCurrentDirectory: LPCWSTR;
  const lpStartupInfo: STARTUPINFOW;
  var lpProcessInformation: PROCESS_INFORMATION
  ): BOOL; overload; stdcall;
 

and

function CreateProcessW(
  lpApplicationName: LPCWSTR;
  lpCommandLine: PByte;
  lpProcessAttributes, lpThreadAttributes: LPSECURITY_ATTRIBUTES;
  bInheritHandles: BOOL;
  dwCreationFlags: DWORD;
  lpEnvironment: LPVOID;
  lpCurrentDirectory: LPCWSTR;
  const lpStartupInfo: STARTUPINFOW;
  var lpProcessInformation: PROCESS_INFORMATION
  ): BOOL; overload; stdcall;
 

I choose PByte in the second declaration because it allows for nil but disallows PChar(‘notepad.exe’) which will also AV.

So what do you think? Should we change this in Jwa?