现需要在.Net环境中使用C#操作C++的dll,但不知如何下手,请高手指教,如有具体例子,可发邮件到我信箱中,不胜感激。

解决方案 »

  1.   

    跟调用API函数一样:
    [DllImport("user32.dll",CharSet="CharSet.Auto",EntryPoint="MessageBox")]
    public static extern int MsgBox(IntPtr hWnd,string txt,string caption, int type);如果是com的话引用一下就行了
      

  2.   

    C++代码:
    BOOL APIENTRY DllMain( HANDLE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved )
    {
    return TRUE;
    }
    int IntTest(int* a,int* b)   
    {                                                   
    return *a + *b;                                 
    }
    C#代码:
    class MyClass
    {
    [DllImport("StandardDll.dll",CharSet=CharSet.Auto,EntryPoint="IntTest")]
    static extern int Test(ref int a,ref int b);
    public static void Main()
    {
    int a = 10;
    int b = 2;
    int c = Test(ref a,ref b);
    Console.WriteLine(c);
    }
    }
      

  3.   

    找不到类型或命名空间名称“DllImport”(是否缺少 using 指令或程序集引用?)请问这个问题如何解决阿?
    还有6.0的dll是否要在解决方案中引用?
      

  4.   

    我已知需using System.Runtime.InteropServices;
    但是依然不知6.0的dll应该放在.Net解决方案目录中的什么位置,请告知!