怎么引用MFC dll工程生成的dll,
在C#中 using不了 ?指点下
高手

解决方案 »

  1.   

    类似于这样
    [DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
    private static extern SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);
      

  2.   

    标准的`DLL就是这么调用的,没有其他方法了
    USING那个只用于.NET下生成的装配件
      

  3.   

            [DllImport("Kernel32.dll")]
            internal static extern IntPtr LoadLibrary(string file);        [DllImport("Kernel32.dll")]
            internal static extern IntPtr GetProcAddress(
                IntPtr module,
                [MarshalAs(UnmanagedType.LPStr)] string procName);
            internal delegate bool TestFunction(param1,param2...);         string path = dll的路径; // 自己添加代码
             IntPtr dllHandle = Win32Api.LoadLibrary(path); 
             if (dllHandle == (IntPtr)null) { return ; }         IntPtr proc = GetProcAddress(dllHandle, "TestFunction");
             if (proc != (IntPtr)null)
             {
                 TestFunction func = (TestFunction)Marshal.GetDelegateForFunctionPointer(proc, 
                                                                          typeof(TestFunction));
             }
             else
             { return; }
             这样 func函数 跟dll中的TestFunction是一个功能. 通过使用func 来代替使用dll中的TestFunction.
      

  4.   

    把.dll文件添加引用了试试..