找回密码
 加入
搜索
查看: 3352|回复: 12

两个au3文件之间如何传递参数?

[复制链接]
发表于 2008-5-3 23:28:43 | 显示全部楼层 |阅读模式
请教大家:
运行文件A时,调用运行文件B,传递一个参数给B,文件B执行完后,再传回一个参数给A,
如何操作?

[ 本帖最后由 adminauto 于 2008-6-18 19:58 编辑 ]
 楼主| 发表于 2008-5-4 01:07:29 | 显示全部楼层
已经实现从A传递给B,
A.au3
code:
ShellExecuteWait("B.exe","kk")

B.au3
code:
if $cmdline[1]="kk" Then
        MsgBox(0,"kk",$cmdline[1])
Else
        msgbox(0,"kk","没有参数")
EndIf


但还是不知道B如何再传回给A。
发表于 2008-5-4 01:37:54 | 显示全部楼层
为什么要分2个文件调用 写成函数形式不好么
发表于 2008-5-4 10:14:00 | 显示全部楼层
这个就是有点像调用DLL调函数吧?AU3好像没有这样的功能,可能你要用其他语言工具写个DLL了
 楼主| 发表于 2008-5-4 11:37:40 | 显示全部楼层
A文件要调用20多个文件可执行文件,如果每个都写成函数,不是很麻烦?
而且要根据前一个程序的执行的结果再执行下一个程序。

DLL调函数?不懂啊?
发表于 2008-5-4 12:28:34 | 显示全部楼层
应该就是想把这两个做成类似那个  一个服务端一个客户端  的吧  客户端请求,服务端响应
发表于 2008-5-4 21:07:15 | 显示全部楼层
依楼主字面理解,个人想法是最好合成一个程序来做,这样会很方便,
如果一定要是两个程序,可以试试启用UDP/TCP协议来个本机收发信息以传递相互间的消息。
 楼主| 发表于 2008-5-4 21:48:54 | 显示全部楼层
摸索了一下午,找到一个解决方法,改用第三方作为参数的传递者,
新建一个INI配置文件,
[file]
t_value=参数

1.A调用B程序时的参数已经在2楼给出方法,
2.当B执行完后,就把结果写回INI配置文件中“参数”,
3.当A再调用C的时候,先检查B的执行结果,再先进选择是否要执行。
发表于 2008-5-4 22:58:12 | 显示全部楼层
;B文件
If $Cmdline[0] Then Exit 1;有参数以返回1退出
Exit 0;无参数以返回0退出

;A文件
$ver = RunWait("b.exe 参数")
MsgBox(0, "B文件返回值", $ver )
$ver = RunWait("b.exe")
MsgBox(0, "B文件返回值", $ver )

编译B文件后运行A
发表于 2008-5-5 13:35:17 | 显示全部楼层
WM_COPYDATA消息
 楼主| 发表于 2008-5-5 20:58:35 | 显示全部楼层
用WM_COPYDATA消息来实现两个进程之间传递数据  
作者: 来源:xfbbs 发布时间:2006.08.13

简介: 本文着重讲述了如果用WM_COPYDATA消息来实现两个进程之间传递数据. 进程之间通讯的几种方法: 在Windows程序中,各个进程之间常常需要交换数据,进行数据通讯。常用的方法有   使用内存映射文件
  通过共享内存DLL共享内存
  使用SendMessage向另一进程发送WM_COPYDATA消息比起前两种的复杂实现来,WM_COPYDATA消息无疑是一种经济实惠的一中方法. WM_COPYDATA消息的主要目的是允许在进程间传递只读数据。Windows在通过WM_COPYDATA消息传递期间,不提供继承同步方式。SDK文档推荐用户使用SendMessage函数,接受方在数据拷贝完成前不返回,这样发送方就不可能删除和修改数据: 这个函数的原型及其要用到的结构如下: SendMessage(hwnd,WM_COPYDATA,wParam,lParam);
其中,WM_COPYDATA对应的十六进制数为0x004A wParam设置为包含数据的窗口的句柄。lParam指向一个COPYDATASTRUCT的结构:
typedef struct tagCOPYDATASTRUCT{
    DWORD dwData;//用户定义数据
    DWORD cbData;//数据大小
    PVOID lpData;//指向数据的指针
}COPYDATASTRUCT;
该结构用来定义用户数据。 具体过程如下:
首先,在发送方,用FindWindow找到接受方的句柄,然后向接受方发送WM_COPYDATA消息. 接受方在DefWndProc事件中,来处理这条消息.由于中文编码是两个字节,所以传递中文时候字节长度要搞清楚. 代码中有适量的解释,大家请自己看吧. 具体代码如下:
//---------------------------------------------------
//发送方:
//--------------------------------------------------- using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices; namespace WindowsFormGetMsg
{
public class Form1 : System.Windows.Forms.Form
{
  private System.Windows.Forms.TextBox textBox1;
  private System.ComponentModel.Container components = null;
  const int WM_COPYDATA = 0x004A;   public Form1()
  {
   InitializeComponent();
  }   protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }   #region Windows Form Designer generated code
  private void InitializeComponent()
  {
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.SuspendLayout();
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point (176, 32);
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(160, 21);
   this.textBox1.TabIndex = 0;
   this.textBox1.Text = "textBox1";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(432, 266);
   this.Controls.AddRange(new System.Windows.Forms.Control[] {
                     this.textBox1});
   this.Name = "Form1";
   this.Text = "接收方";
   this.ResumeLayout(false);   }
  #endregion   [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }   protected override void DefWndProc(ref System.Windows.Forms.Message m)
  {
   switch(m.Msg)
   {
     //接收自定义消息 USER,并显示其参数
    case WM_COPYDATA:
     COPYDATASTRUCT mystr = new COPYDATASTRUCT();
       Type mytype = mystr.GetType();        mystr =(COPYDATASTRUCT)m.GetLParam(mytype);
     this.textBox1.Text  =mystr.lpData;      break;
    default:
     base.DefWndProc(ref m);
     break;    }   }  }
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
  public IntPtr dwData;
  public int cbData;
  [MarshalAs(UnmanagedType.LPStr)] public string lpData;
}
}
//---------------------------------------------------
//接受方
//---------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices; namespace WindowsFormGetMsg
{
public class Form1 : System.Windows.Forms.Form
{
  private System.Windows.Forms.TextBox textBox1;
  private System.ComponentModel.Container components = null;
  const int WM_COPYDATA = 0x004A;   public Form1()
  {
   InitializeComponent();
  }   protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }   #region Windows Form Designer generated code
  private void InitializeComponent()
  {
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.SuspendLayout();
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point (176, 32);
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(160, 21);
   this.textBox1.TabIndex = 0;
   this.textBox1.Text = "textBox1";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(432, 266);
   this.Controls.AddRange(new System.Windows.Forms.Control[] {
                     this.textBox1});
   this.Name = "Form1";
   this.Text = "接收方";
   this.ResumeLayout(false);   }
  #endregion   [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }   protected override void DefWndProc(ref System.Windows.Forms.Message m)
  {
   switch(m.Msg)
   {
     //接收自定义消息 USER,并显示其参数
    case WM_COPYDATA:
     COPYDATASTRUCT mystr = new COPYDATASTRUCT();
       Type mytype = mystr.GetType();        mystr =(COPYDATASTRUCT)m.GetLParam(mytype);
     this.textBox1.Text  =mystr.lpData;      break;
    default:
     base.DefWndProc(ref m);
     break;    }   }  }
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
  public IntPtr dwData;
  public int cbData;
  [MarshalAs(UnmanagedType.LPStr)] public string lpData;
}
}

用autoit如何实现?
发表于 2008-5-5 22:37:28 | 显示全部楼层
发表于 2011-3-5 16:39:52 | 显示全部楼层
最近在研究这个,收藏个以备参考!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-1 19:21 , Processed in 0.086921 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表