这些都是用X3Importer中的DelphiImporter.exe生成的DLL和BPL,在delphi的测试工程里引用运行时出现初始化失败的错误,无法使用,但是同样的代码使用delphi直接生成DLL文件使用没有问题
DLL的代码:
library RarpEx;
uses
ShareMem,
SysUtils,
Classes,
Windows, Dialogs;
{$R *.res}
function RarProcess(ACmdLine :string;var hProcess,hThread:Cardinal):Boolean;stdcall;
var
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
begin
FillChar(StartUpInfo, SizeOf(StartUpInfo), 00);
StartupInfo.cb:=SizeOf(StartupInfo);
StartupInfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
StartupInfo.wShowWindow := SW_HIDE;
if not CreateProcess(nil,PChar(ACmdLine),nil,nil,False,
CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
nil,nil, StartupInfo, ProcessInfo) then
begin
Result := false;
exit;
end;
hProcess := ProcessInfo.hProcess;
hThread := ProcessInfo.hThread;
Result := true;
end;
exports
RarProcess;
begin
end.
测试工程的代码:
unit testForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function RarProcess(ACmdLine : String;var hProcess,hThread: Cardinal):Boolean;stdcall;external 'RarpEx.dll'
procedure TForm1.Button1Click(Sender: TObject);
var
hProcess,hThread : Cardinal;
lb : boolean;
lCmdLine : string;
begin
lCmdLine := Edit2.Text;
//lCmdLine := 'F:\temp\winrar.exe a -r F:\temp\test.rar F:\temp\Test';
lb := RarProcess(lCmdLine,hProcess,hThread);
if lb then
begin
WaitForSingleObject(hProcess, INFINITE);
CloseHandle(hProcess);
CloseHandle(hThread);
end;
end;
end. |