Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Delphi Prism中调用函数CreateProcess?_Delphi_Dll_Createprocess_Delphi Prism_Oxygene - Fatal编程技术网

如何在Delphi Prism中调用函数CreateProcess?

如何在Delphi Prism中调用函数CreateProcess?,delphi,dll,createprocess,delphi-prism,oxygene,Delphi,Dll,Createprocess,Delphi Prism,Oxygene,我写 但是VStudio说应该在外部后面加上“分号”,在“kernel32.dll”后面加上“end”; 你能帮我加载并调用一个函数吗?@Ilya,你调用外部函数时使用了错误的语法。您需要使用DllImport关键字才能使Windows互操作正常工作 您必须将函数重写为 function CreateProcess( lpApplicationName:String; lpCommandLine:String; lpProc

我写

但是VStudio说应该在外部后面加上“分号”,在“kernel32.dll”后面加上“end”;
你能帮我加载并调用一个函数吗?

@Ilya,你调用外部函数时使用了错误的语法。您需要使用
DllImport
关键字才能使Windows互操作正常工作

您必须将函数重写为

function CreateProcess(
            lpApplicationName:String;
            lpCommandLine:String;
            lpProcessAttributes:IntPtr;
            lpThreadAttributes:IntPtr;
            bInheritHandles:Boolean;
            dwCreationFlags:Int32;
            lpEnvironment:IntPtr;
            lpCurrentDirectory:IntPtr;
            lpStartupInfo:STARTUPINFO;
            lpProcessInformation:ProcessInfo):Boolean;
         external 'kernel32.dll';
检查这个工作样本

[DllImport("kernel32.dll")]
class function CreateProcess(
            lpApplicationName:String;
            lpCommandLine:String;
            lpProcessAttributes:IntPtr;
            lpThreadAttributes:IntPtr;
            bInheritHandles:Boolean;
            dwCreationFlags:Int32;
            lpEnvironment:IntPtr;
            lpCurrentDirectory:IntPtr;
            lpStartupInfo:STARTUPINFO;
            lpProcessInformation:ProcessInfo):Boolean; external;
查看这些链接以获取更多信息


    • 为什么不使用.NET进程类。。在这种情况下使用互操作没有多大意义,因为您已经在使用Delphi Prism


      +1;关于.NET的重点不是学习一种语言来编程,而是学习并利用.NET框架中的内容。.NET框架非常庞大:
      namespace ConsoleApplication20;
      
      interface
      uses
          System.Diagnostics,
          System.Runtime.InteropServices;
      
      
      type
      PROCESS_INFORMATION =record
          hProcess    : IntPtr;
          hThread     : IntPtr;
          dwProcessId : UInt32;
          dwThreadId  : UInt32;
      end;
      
      
      
      STARTUPINFO =record
           cb       : UInt32;
          lpReserved: String;
          lpDesktop : String;
          lpTitle   : String;
          dwX       : UInt32;
          dwY       : UInt32;
          dwXSize   : UInt32;
          dYSize    : UInt32;
          dwXCountChars   : UInt32;
          dwYCountChars   : UInt32;
          dwFillAttribute : UInt32;
          dwFlags         : UInt32;
          wShowWindow : ShortInt;
          cbReserved2 : ShortInt;
          lpReserved2 : IntPtr;
          hStdInput   : IntPtr;
          hStdOutput  : IntPtr;
          hStdError   : IntPtr;
      end;
      
        ConsoleApp = class
        private
          [DllImport("kernel32.dll")]
          class method CreateProcess( lpApplicationName: string;  lpCommandLine:string;  lpProcessAttributes:IntPtr; lpThreadAttributes:IntPtr;
                              bInheritHandles:Boolean;dwCreationFlags: UInt32;  lpEnvironment:IntPtr;
                              lpCurrentDirectory:string;var lpStartupInfo:STARTUPINFO;out lpProcessInformation:PROCESS_INFORMATION) : boolean; external;
        public
          class method Main;
        end;
      
      implementation
      
      class method ConsoleApp.Main;
      var
      lpStartupInfo        : STARTUPINFO;
      lpProcessInformation : PROCESS_INFORMATION;
      begin
              lpStartupInfo := new STARTUPINFO();
              lpProcessInformation := new PROCESS_INFORMATION();
              Console.WriteLine('Creating Process');
              CreateProcess('C:\WINDOWS\SYSTEM32\notepad.exe', nil, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, nil, var lpStartupInfo, out lpProcessInformation);
              Console.ReadLine();
      end;
      
      end.