相关疑难解决方法(0)

在Delphi 2009中的函数CreateProcess中访问冲突

在我的程序中,我有以下代码:

//Code
 if not CreateProcess(nil, NonConstCmd, nil, nil, True, NORMAL_PRIORITY_CLASS or
    CREATE_NEW_PROCESS_GROUP, nil, PCh, SI, P) then
//Code
Run Code Online (Sandbox Code Playgroud)

并且我一直收到访问冲突错误.顺便说一下,在Delphi7中,相同的代码完美地运行.我读过MSDN,发现Delphi中的CreateProcess函数可以修改第二个参数.初始它是const,这就是为什么我创建一个具有相同值的新变量.但它没有任何效果.

问题是:为什么这段代码不起作用?

delphi createprocess delphi-2009 access-violation

10
推荐指数
2
解决办法
4329
查看次数

SetProcessAffinityMask - 选择多个处理器?

如何使用SetProcessAffinityMask选择多个逻辑处理器?

在Windows任务管理器中,您可以将此作为示例:

在此输入图像描述

我更新了我的CreateProcess过程来执行此操作:

type
  TProcessPriority = (ptLow         = $00000040,
                      ptBelowNormal = $00004000,
                      ptNormal      = $00000020,
                      ptAboveNormal = $00008000,
                      ptHigh        = $00000080,
                      ptRealtime    = $00000100);

procedure RunProcess(FileName: string; Priority: TProcessPriority);
var
  StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  CmdLine: string;
  Done: Boolean;
begin
  FillChar(StartInfo, SizeOf(TStartupInfo), #0);
  FillChar(ProcInfo, SizeOf(TProcessInformation), #0);
  StartInfo.cb := SizeOf(TStartupInfo);

  CmdLine := FileName;
  UniqueString(CmdLine);
  try
    Done := CreateProcess(nil, PChar(CmdLine), nil, nil, False,
                          CREATE_NEW_PROCESS_GROUP + Integer(Priority),
                          nil, nil, StartInfo, ProcInfo);
    if Done then
    begin
      // Todo: Get actual cpu core count …
Run Code Online (Sandbox Code Playgroud)

delphi delphi-xe

8
推荐指数
2
解决办法
4702
查看次数