首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#调用C++dll的有关问题!

2013-09-08 
c#调用C++dll的问题!!c#代码[DllImport(CDLlDemo.dll, EntryPoint wori)]public extern static int

c#调用C++dll的问题!!
c#代码
[DllImport("CDLlDemo.dll", EntryPoint = "wori")]
public extern static int wori();
private void button1_Click(object sender, EventArgs e)
{
      textBox1.Text =wori().ToString();
}

c++代码 cpp
int CDLlDemo::wori() {
return 3+5;
}

h
#ifndef CDLLDEMO_H_
#define CDLLDEMO_H_

class CDLlDemo {
public:
CDLlDemo();
virtual ~CDLlDemo();
virtual int wori();
};

#endif /* CDLLDEMO_H_ */
[解决办法]
可有加.def文件导出函数?
要么用def文件导出函数,要么在函数声明中加上__declspec(dllexport)
[解决办法]
头文件没定义dll入口吧

#ifdef YOURDLL
#define YOURDLL extern "C" _declspec(dllimport) 
#else
#define YOURDLL extern "C" _declspec(dllexport) 
#endif

YOURDLL int your_function( );

热点排行