日期:2014-05-17  浏览次数:20800 次

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( );