我碰到一个VC写非受托管函数  
比如:
void a(b);void b(DWORD dwEventType)
{.....}
要转用c#来调用a这个外部函数

解决方案 »

  1.   

    看看这个代码:
    .net里用delegate实现“通过方法名的字符串调用方法” 以一个private void Jump1()为调用原型!public class test
    {
     private delegate void JumpBoxDelegate(); //----调用的方法----- private void Jump1()
     {
      MessageBox.Show("Jump1");
     } private void Jump2()
     {
      MessageBox.Show("Jump2");
     }
     //-----------------------------
     public void InvokeJump(string MethodName)
     {
        //这里可以加上判断,检测MethodName的方法是否存在
      Type t=typeof(JumpBoxDelegate);
      Delegate objDelegate=Delegate.CreateDelegate(t,this,MethodName,true);
      objDelegate.DynamicInvoke(null);
     }
    }
      

  2.   

    delegate void fptest(int i);
    static void test(int i)
    {
      Console.WriteLine(i);
    }...fptest ft = new fptest(test);
    ft(128);