例如很多年前我用C++ 6.0做的一个类
class sampleclass
{
int a,b,c;
public int fun1();
{
return a+b-c;}
public int fun2();
{
return a*b-c;}...}
已经把他包装成一个dll (C++ 6.0)现在在C#的环境中 我想把这个类倒进来 ,在代码中 也能 写出 像 sampleclass aa=new sampleclass(); 进行类似aa.fun1(); aa.fun2();的操作
我想问在C#中怎么实现这样的效果啊。 对在c++中的dll文件?编译有什么要求?
class sampleclass
{
int a,b,c;
public int fun1();
{
return a+b-c;}
public int fun2();
{
return a*b-c;}...}
已经把他包装成一个dll (C++ 6.0)现在在C#的环境中 我想把这个类倒进来 ,在代码中 也能 写出 像 sampleclass aa=new sampleclass(); 进行类似aa.fun1(); aa.fun2();的操作
我想问在C#中怎么实现这样的效果啊。 对在c++中的dll文件?编译有什么要求?
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApplication3
{
class Program
{ [DllImport("dll路径", EntryPoint = "fun1", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int fun1(string str); static void Main(string[] args)
{
try
{
int result = fun1();
Console.WriteLine(result);
Console.Read(); }
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.Read();
}
} }
}测试下,看可以吗,有什么问题再问我。
但是运行时报 找不到dll中的 fun1 入口?
dll中到底应该怎么写 这个类呢?