如何让运行着的程序接收命令行输入的参数?(200分)

  • 主题发起人 主题发起人 kylin_2000
  • 开始时间 开始时间
K

kylin_2000

Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序是:mms.exe<br>由于程序是对硬件操作的,所以程序必须一直运行着。<br>现在的问题是:当我通过命令行如:mms.exe -auto -delete 的方式调用程序,而这个程序由于是对硬件的操作的所以不能重新启动程序,只能给已经运行着的程序发送消息,运行中的程序根据接收到的消息再进行相关的处理。<br>请高人指点,解决后立即给分。
 
mms.exe是什么程序, 控制台? 标准win32?
 
就是我自己写的程序
 
是标准的win32
 
那就发送消息吧
 
program Project1;<br>uses<br> &nbsp;Forms,<br> &nbsp;Windows,<br> &nbsp;Messages,<br> &nbsp;SysUtils,<br> &nbsp;Unit1 in 'Unit1.pas' {Form1};<br><br>{$R *.res}<br><br>procedure SendParamMsg(Handle: THandle; Msg:String);<br>var <br> DS: TCopyDataStruct; <br>begin<br> Ds.cbData:=Length(Msg) + 1; <br> GetMem(Ds.lpData, Ds.cbData ); &nbsp; &nbsp; &nbsp; &nbsp; <br> StrCopy(ds.lpData,PChar(Msg)); <br> SendMessage(Handle, WM_COPYDATA, Application.Handle,Cardinal(@ds)); <br> FreeMem(Ds.lpData);<br>end;<br><br>var <br> &nbsp;h: THandle;<br> &nbsp;i: integer;<br>begin<br> &nbsp;Application.Initialize;<br> &nbsp;h:=FindWindow('TForm1', nil);<br> &nbsp;if (h&lt;&gt;0) and (ParamCount &gt; 0) then<br> &nbsp;begin<br> &nbsp; &nbsp;for i:=1 to ParamCount do<br> &nbsp; &nbsp; &nbsp;SendParamMsg(h, ParamStr(i));<br> &nbsp; &nbsp;Halt;<br> &nbsp;end;<br> &nbsp;Application.CreateForm(TForm1, Form1);<br> &nbsp;Application.Run;<br>end.<br><br>---------------<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StrUtils, StdCtrls;<br><br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;procedure ParamMessage(var msg: TWMCopyData);Message WM_COPYDATA; <br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.ParamMessage(var msg:TWMCopyData);<br>var<br> &nbsp;s:String; <br>begin<br> s:=StrPas(msg.CopyDataStruct^.lpData);<br> //在这里处理消息字符<br> Memo1.Lines.Add(s);<br>end;
 
后退
顶部