当前位置:编程学习 > C#/ASP.NET >>

winform之间调用的问题

有一个应用程序1.exe(可能是c#编写的,也可能是其他语言写的,如delphi)
现在需要用c#开发一个执行文件或者dll库(2.exe或者2.dll)
当点击1.exe中的一个按钮时,传入一个参数给2.exe或者2.dll,弹出窗体,
请问大虾们怎么做啊,最好有实例代码 --------------------编程问答-------------------- socket通讯,或发送windows消息 --------------------编程问答--------------------
引用 1 楼 gxingmin 的回复:
socket通讯,或发送windows消息

但是2.exe或者2.dll本身没有打开啊,是点击1.exe中的按钮才会打开
这个时候做不了socket吧
发送windows消息有没有实例代码啊 --------------------编程问答-------------------- 可以使用消息通讯,或者模拟键盘操作。 --------------------编程问答-------------------- 哦,那在2 .exe里接收命令行参数

如:
static void Main(string []args)
{
    if(args.Length>0 && args[0]=="****") 
     {
         Form1 frm=new Form1();
         frm.ShowDialog();
    }
} --------------------编程问答--------------------
引用 4 楼 gxingmin 的回复:
哦,那在2 .exe里接收命令行参数

如:
static void Main(string []args)
{
    if(args.Length>0 && args[0]=="****") 
     {
         Form1 frm=new Form1();
         frm.ShowDialog();
    }……


谢谢了
能不能把1.exe 怎么传进去,2怎么接受写详细点啊 --------------------编程问答-------------------- 顶起来哈!! --------------------编程问答-------------------- 进程之间通信
 发送端
   [DllImport("user32.dll", EntryPoint = "SendMessageA")]
   private static extern int SendMessage(IntPtr hwnd,int wMsg, IntPtr wParam,int lParam);
   [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
   private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    public class A
    {
        public const int USER = 0x0400;
        public const int WM_TEST = USER + 101;
    }
    private void button1_Click(object sender, EventArgs e)
    {
      //在点击按钮时,调用进程打开2.EXE。
      IntPtr ptrWnd = FindWindow(null, "窗口进程名称");
      if (ptrWnd != null)
       {
          SendMessage(ptrWnd, A.WM_TEST, IntPtr.Zero, 2);
       }
         
    }
接收端
     public class A
    {
        public const int USER = 0x0400;
        public const int WM_TEST = USER + 101;
    }
 protected override void DefWndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
      
                case A.WM_TEST:
                 string message = string.Format("收到从应用程序发出的消息!参数为:{0},{1}", m.WParam, m.LParam);
                   
                    MessageBox.Show(message);
                    break;
                default:
                    base.DefWndProc(ref m);//调用基类函数处理非自定义消息。
                    break;
            }
        } --------------------编程问答--------------------
引用 4 楼 gxingmin 的回复:
static void Main(string []args)
{
    if(args.Length>0 && args[0]=="****") 
     {
         Form1 frm=new Form1();
         frm.ShowDialog();
    }……



正解..

启动的话 带参数就行了 比如 在D盘的话 就启动

d\1.exe  t1 t2 t3

这个t1 t2 t3就是 string []args了 --------------------编程问答--------------------             Assembly assembly = Assembly.Load(" ");
            Type type = assembly.GetType(" ");
            object[] objs = new object[] {   };
            Type[] types = new Type[] { typeof(string), typeof(string), typeof(int), typeof(int), typeof(string), typeof(int), typeof(int) };
            ConstructorInfo constructorInfoObj = type.GetConstructor(types);
            if (constructorInfoObj == null)
                XtraMessageBox.Show(" Load Failed !");
            object obj = constructorInfoObj.Invoke(objs);
            XtraForm frm = obj as XtraForm;
            frm.ShowDialog();
这种是利用构造函数传参的方法 
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,