以前在VB.NET的时候,有一个取得某地址数据的类,是用这种方法传的(使用WIN API时)
都是.NET,用的类库是一样的,不过记不清了.搜索一下吧问题2不知何意???

解决方案 »

  1.   

    问题2是指以前WM_USER+100 实现向程序发送自定义消息
      

  2.   

    1:你说的函数指针我不知道是具体什么,应该是委托吧(不太清楚,也就不在回答了)
    2:给你个示例
    public class MsgEventArgs : System.EventArgs
    {
    private string dataStr ;
    public MsgEventArgs()
    {}
    }public class ExampleClass
    {
        public delegate void ExampleEventMsgHandler(object sender,MainFrame.MsgEventArgs e);
        public event ExampleEventMsgHandler ExampleEvent;    public void TigerEvent(){      MsgEventArgs msg = new MsgEventArgs ();
         msg.dataStr      = ...;     if( ExampleEvent != null ){
             ExampleEvent( null , msg );
         }
       }
    }
    //在这个类中定义了上面类的事件
    public class ExampleEventClass 
    {
        ExampleClass exa = new ExampleClass();    public ExampleEventClass ()
       {  
           exa . ExampleEvent += new  ExampleEventMsgHandler( EventProcess );
       }
        public void EventProcess (object sender,MainFrame.MsgEventArgs e){
             //use e
         //Controls.WriteLine( e.dataStr );
        }      
    }
    //供参考
      

  3.   

    自定义消息?是用于发送窗口消息那样的么?
    你找一个没有系统的消息里面没有用过的数值,然后这样定义:
    const int WM_MYMSG = 0x0101;
    不过发送方和接收方要有同样的定义。
      

  4.   

    我想,大家可能还没清楚我的意思,关于第一个问题是在调用外部动态链接库的时候(DLL),参数为函数指针,请问在C#中如何实现,应注意什么问题
    第二个问题好像kerlw(科尔)似乎已经了解了,问题是请问如何传送消息和接收消息
    以上两个问题请都举例
      

  5.   

    1.
    using System;
    using System.Runtime.InteropServices;public delegate bool CallBack(int hwnd, int lParam);public class EnumReportApp {    [DllImport("user32")]
        public static extern int EnumWindows(CallBack x, int y);     public static void Main() 
        {
            CallBack myCallBack = new CallBack(EnumReportApp.Report);
            EnumWindows(myCallBack, 0);
        }   public static bool Report(int hwnd, int lParam) { 
            Console.Write("Window handle is ");
            Console.WriteLine(hwnd);
            return true;
        }
    }
    2.见FAG中
    用SendMessage