Figured I'd mention that if you supply a literal string as the lpCommandLine argument within CreateProcessExW you will receive an access violation guaranteed. To fix this inherent Windows issue with CreateProcessW problem you can just copy the lpCommandLine argument to the stack before calling the underlying Windows API CreateProcessW in your CreateProcessExW wrapper. If you don't feel that it's necessary since this is documented behavior of CreateProcessW you may want to let your users know that you are calling this API and that literal strings are not to be used.
MSDN says this about CreateProcessW()
This Crashes: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.
Code: Select all
var
si: STARTUPINFO;
pi: PROCESS_INFORMATION;
begin
GetStartupInfoW(si);
CreateProcessExW(nil, 'calc.exe', nil, nil, False, 0, nil, nil, si, pi, 'Dummy.dll');
end;
Code: Select all
var
lpBufW: Array [0..MAX_PATH] of WCHAR;
si: STARTUPINFO;
pi: PROCESS_INFORMATION;
begin
ZeroMemory(@lpBufW, sizeof(lpBufW));
lstrcpyW(@lpBufW, 'calc.exe');
GetStartupInfoW(si);
CreateProcessExW(nil, @lpBufW, nil, nil, False, 0, nil, nil, si, pi, 'Dummy.dll');
end;