怎样在c#中调用c++的静态方法
在一个解决方案下面有两个工程,分别用c#和c++编写,都是托管代码。
在工程一中的命名空间NameA下有c++代码,如下:
namespace NameA
{
public class ClassA
{
public:
static void FunctionA();
}
}    
在工程二的命名空间NameB下有c#代码,如下:
using NameA;
namespace NameB
{
public class ClassB
{
public void FunctionB()
{
NameA.FunctionA();//报错,NameA这个类是存在的,但该方法不存在?
}
}
}    
大家帮我,怎么才能正确调用呢?

解决方案 »

  1.   

      [DllImport("DllDemo.dll", EntryPoint = "Add", ExactSpelling =false, CallingConvention = CallingConvention.Cdecl)]
            public static extern int Add(int a,int b);   private void button1_Click(object sender, EventArgs e)
            {
                textBox1.Text=Add(1, 2).ToString();        }
      

  2.   

    DLL说明
    1 在C++那明确指定__stdcall 声明
    即 extern "C" __declspec(dllexport) static __stdcall void Function(); 说明为导出
    2 在C#里1 需要
    [DllImport("哪个DLL",哪个函数)]
    下面声明一样即可以C++的类型对应C#的类型 就不说了
      

  3.   

    在c#项目里引用里设置一下C++的dll
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  4.   


    1楼正确.
    [DllImport("DllDemo.dll", EntryPoint = "Add", ExactSpelling =false, CallingConvention = CallingConvention.Cdecl)] 
    public static extern int Add(int a,int b); 这些地方你对着修改试试