delphi怎么实现外部程序调用以及调用的外部程序关闭时,返回一个值

delphi怎么实现外部程序调用以及调用的外部程序关闭时,返回一个值,第1张

用下面这个函数可以解决你的问题:

function  WinExecAndWait32(FileName:String;  Visibility  :  integer):  DWORD;  

var  

        zAppName:array[0512]  of  char;

        zCurDir:array[0255]  of  char;

        WorkDir:String;

        StartupInfo:TStartupInfo;

        ProcessInfo:TProcessInformation;

begin

        StrPCopy(zAppName,FileName);

        GetDir(0,WorkDir);

        StrPCopy(zCurDir,WorkDir);

        FillChar(StartupInfo,Sizeof(StartupInfo),#0);

        StartupInfocb  :=  Sizeof(StartupInfo);

        StartupInfodwFlags  :=  STARTF_USESHOWWINDOW;

        StartupInfowShowWindow  :=  Visibility;

        if  not  CreateProcess(

        nil,

        zAppName,  {  pointer  to  command  line  string  }

        nil,  {  pointer  to  process  security  attributes  }

        nil,  {  pointer  to  thread  security  attributes  }

        false,  {  handle  inheritance  flag  }

        CREATE_NEW_CONSOLE  or  {  creation  flags  }

        NORMAL_PRIORITY_CLASS,

        nil,  {  pointer  to  new  environment  block  }

        nil,  {  pointer  to  current  directory  name  }

        StartupInfo,  {  pointer  to  STARTUPINFO  }

        ProcessInfo  {  pointer  to  PROCESS_INF  }

        )

        then  Result  :=  $FFFFFFFF  else  begin

                WaitforSingleObject(ProcessInfohProcess,INFINITE);

                GetExitCodeProcess(ProcessInfohProcess,Result);

        end;

end;

c#调用外部exe程序,首先要

using SystemDiagnostics;

然后开启一个新process

SystemDiagnosticsProcessStartInfo p=null;

SystemDiagnosticsProcess Proc;

p = new ProcessStartInfo("nnnnexe","参数");

pWorkingDirectory = exepath;//设置此外部程序所在windows目录

Proc = SystemDiagnosticsProcessStart(p);//调用外部程序

打开visual studio创建一个控制台应用程序在解决方案中再添加一个新的类库项目,使用默认名称ClassLibrary1用于模拟dll在控制台应用程序ConsoleApp1的引用上点击鼠标右键,选择添加引用勾选上面的类库项目,将其添加进来如果没有源码的dll,也可以通过添加引用,将其dll引入到当前项目中在新建的类库项目中添加一个方法,返回系统当前时间的字符串表示值。在控制台应用程序中调用这个方法在需要调试的方法行,最左边点击一下,就可以在此处设置一个vs调试断点在vs中按F5,就可以进入调试模式,当代码运行到断点处会自动暂停,此时按F11,就可以进入到dll方法内部去,需要有两个前提vs当前处于Debug调试模式外部dll引入进来的需要时debug版本,如果是release版本是不能调试的F11进来后就可以看到调试dll的效果了。继续运行完成后,界面就输出了系统当前日期到控制台

利用TCP实现数据库与外部程序通讯,让数据库服务器通知一个守护程序去执行程序。

set serveroutput on size 100000

DECLARE

c utl_tcpconnection; -- TCP/IP connection to the Web server

i number;

j number;

BEGIN

c := utl_tcpopen_connection('1018111', 51000); -- open connection

begin

loop

i := utl_tcpavailable(c);

exit when i<=0;

dbms_outputput_line('READ='||To_Char(i));

-- while i>0 loop

dbms_outputput(utl_tcpget_text(c,i)); -- read result

-- i :=i-1;

-- end loop;

end loop;

exception

when others then null;

end;

dbms_outputput_line('');

i := utl_tcpwrite_line(c, 'HELLO WORLD');

dbms_outputput_line('WRITE='||To_Char(i));

begin

j := 0;

loop

i := utl_tcpavailable(c);

if (i=0) then

j := j+1;

if (j>=50) then

exit;

else

for i in 01000 loop

null;

end loop;

end if;

else

dbms_outputput_line('READ='||To_Char(i));

dbms_outputput(utl_tcpget_text(c,i)); -- read result

end if;

end loop;

exception

when others then null;

end;

dbms_outputput_line('');

utl_tcpclose_connection(c);

end;

使用shell语句,例子:

Sub RAR()

    Shell "C:\Program Files\WinRAR\WinRARexe", vbNormalFocus

End Sub

最小化窗口

Process

p

=

new

Process();

pStartInfoFileName

=

@"外部程序位置";

pStartInfoWindowStyle

=

ProcessWindowStyleMinimized;

pStart();

隐藏窗口Process

p

=

new

Process();

pStartInfoFileName

=

@"例如:C:\AllTryexe";

pStartInfoWindowStyle

=

ProcessWindowStyleHidden;

pStart();

注意需要

using

SystemDiagnostics;

以上就是关于delphi怎么实现外部程序调用以及调用的外部程序关闭时,返回一个值全部的内容,包括:delphi怎么实现外部程序调用以及调用的外部程序关闭时,返回一个值、c#中如何启用外部exe程序、C# 如何调试被别的应用程序调用的dll等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zz/10170074.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存