CreateProcess function kernel32

Win32Result<bool> CreateProcess(
  1. PCWSTR? lpApplicationName,
  2. PWSTR? lpCommandLine,
  3. Pointer<SECURITY_ATTRIBUTES>? lpProcessAttributes,
  4. Pointer<SECURITY_ATTRIBUTES>? lpThreadAttributes,
  5. bool bInheritHandles,
  6. PROCESS_CREATION_FLAGS dwCreationFlags,
  7. Pointer<NativeType>? lpEnvironment,
  8. PCWSTR? lpCurrentDirectory,
  9. Pointer<STARTUPINFO> lpStartupInfo,
  10. Pointer<PROCESS_INFORMATION> lpProcessInformation,
)

Creates a new process and its primary thread.

The new process runs in the security context of the calling process.

To learn more, see learn.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw.

Implementation

Win32Result<bool> CreateProcess(
  PCWSTR? lpApplicationName,
  PWSTR? lpCommandLine,
  Pointer<SECURITY_ATTRIBUTES>? lpProcessAttributes,
  Pointer<SECURITY_ATTRIBUTES>? lpThreadAttributes,
  bool bInheritHandles,
  PROCESS_CREATION_FLAGS dwCreationFlags,
  Pointer? lpEnvironment,
  PCWSTR? lpCurrentDirectory,
  Pointer<STARTUPINFO> lpStartupInfo,
  Pointer<PROCESS_INFORMATION> lpProcessInformation,
) {
  final result_ = CreateProcessW_Wrapper(
    lpApplicationName ?? nullptr,
    lpCommandLine ?? nullptr,
    lpProcessAttributes ?? nullptr,
    lpThreadAttributes ?? nullptr,
    bInheritHandles ? TRUE : FALSE,
    dwCreationFlags,
    lpEnvironment ?? nullptr,
    lpCurrentDirectory ?? nullptr,
    lpStartupInfo,
    lpProcessInformation,
  );
  return .new(value: result_.value.i32 != FALSE, error: result_.error);
}