当前位置:编程学习 > C#/ASP.NET >>

C#调用C++非托管dll 请看代码

CS文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CppDemo2
{
    class Program
    {
        [DllImport("cppdemo.dll", EntryPoint = "Add", CharSet = CharSet.Auto)]
        public extern static int Add(int c, int x); 
        static void Main(string[] args)
        {
            int a = Add(1, 2);
            Console.WriteLine(a);
            Console.WriteLine(3);
            Console.Read();
        }
    }
}
cppdemo.dll是在VC6.0写的:
extern "C"_declspec(dllexport) int Add(int a,int b)
{
 return a+b;
}
在VS运行的时候 int a = Add(1, 2);总是说“找不到指定模块”
dll已经放在VS工程下了啊 怎么回事呢  --------------------编程问答-------------------- 放在bin下 --------------------编程问答-------------------- 我也是这个问题 放在bin 下的Debug里面吗?
--------------------编程问答-------------------- 有没有add reference啊 --------------------编程问答-------------------- 是的,也放在工程文件夹下一份
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,