http://chs.gotdotnet.com/quickstart/howto/doc/Interop/PInvoke_Simple.aspx

解决方案 »

  1.   

    请问C#如何调用VC写的dll文件??这个dll是vc6.0写的。
      

  2.   

    写个类接口,给你一个事例看看:
    dll先要在你机器中注册过。
    using System.Runtime.InteropServices;//添加引用
     [DllImport("c:\\winnt\\system32\\smsSdk.dll")]
            public static extern  int  Sms_Connect (string pServer,int lCorpID,string pLoginName,string pPasswd,int lTimeOut,int HWND);//dll中的方法
      

  3.   

    dll请问怎么注册啊?我一点不懂。
      

  4.   

    聲明一下就可以了,現面就是聲明一個用VC寫的Dll,AB_API_Open()就是這個Dll中的一個函數
    //**********************Open**********************************
    [DllImport("dapapi2.dll")]
    public static extern int AB_API_Open();
    調用就和普通函數一樣,AB_API_Open()
      

  5.   

    可是dll里面的函数是这样的 ,我在c#是怎么调用呢?
    OCPE_API int ocpe_deliver_resp(T_OCPE_CONN * Conn, unsigned long seq);
    /*-----------------
    FUNCTION : 回应Deliver
    PARAM
    Conn : 使用的连接
    seq : Deliver的交易流水号
    RETURN
    0 : 发送成功
    -1 : 发送不成功
    -----------------*/
    /////////////////////////////////////////////////////////////////////////////////////////////
    OCPE_API int ocpe_recv(T_OCPE_TRANS * Trans, T_OCPE_CONN * Conn, unsigned short nTimeout);
      

  6.   

    可是dll里面函数的参数在C#是怎么样转化的呢?顶
      

  7.   

    参数转换的话,就看你对两个的语法都要熟悉了。注册:
    regsvr32 xxx.dll
    在命令中注册
      

  8.   

    那么多高手都说了,我就不多说啦,DllImport~~
      

  9.   

    using System.Runtime.InteropServices;public class Win32 {
            ...
            [DllImport("User32.dll", EntryPoint="MessageBox", CharSet=CharSet.Auto)]
            public static extern int MsgBox(int hWnd, String text, String caption, uint type);
    }public class TestPInvoke {
            public static void Main() {
    ...        
    String date = ...;

    Win32.MsgBox(0, date, "PInvoke Sample", 0);
    }
    }
    using System.Runtime.InteropServices;