例如:
    s2k.dll中有个名为S2K_GetDataTableName的函数:
    int S2K_GetDataTableName(char *DataBankName, long Index,int *Buffer_Count, 
                             char *DataTableName);
    其中 DataBankName data bank name
         Index          Reference pointer of data tables in the data bank
        Buffer_Count Specifies the size of the buffer addressed by
        DataTableName A pointer to the buffer area that receives the data table name
    注意:
       DataBankName cannot be more than 255 characters.
    返回值:
       Zero if the function completes successfully; > 0 otherwise.
请问:怎样在c#中调用这个dll,并执行该函数,特别是怎样传递参数,并获得dataTableName

解决方案 »

  1.   

    同意楼上的,你也可以试一下在引用中加了一下这个dll试一下。如果不行,只有采用[DllImport]的方式,注意需要加入 using System.Runtime.InteropServices ,并且要把你的class  声明为:unsafe,同时在你的Project的属性中要允充非托管代码动行。
      

  2.   

    using System.Runtime.InteropServices;[DllImport("XXX.DLL",EntryPoint="GetApiFunction",SetLastError=true)]
    public static extern int GetApiFunction(
        string strParaA,
        StringBuilder strParaB,
        int intParaC,
        out int intParaD,
        bool blnParaE);C++数据类型和C#的部分对应关系:C++           输入输出    C# 
    ==================================
    char chr[255]   O    StringBuilder
    KCA_DIR         I    int
    LPCSTR          I    string
    int             I    int
    LPSTR           O    StringBuilder
    int*            O    out int
    DWORD           I    int
    DWORD*          O    out int
    BOOL            I    bool
    Rc_DBMgr        I    IntPtr
    long*           O    out long
      

  3.   

    1,see [DllImport]
    2,也可以把其他代码编写成DLL,然后在引用中加如就好了