我用向导生成一个Win32 Dynamic-Link Library一个类名叫ab (这是测试用的),
里面新建了一个haha的Class类, 类中新建了一个int mmm(int n)的成员方法,
已经在haha类头文件中加 _declspec(dllexport) int mmm(int n);生成与MFC程序(名ExMFCDLL)关联的DLL,已经把这个DLL放进debug中并设置好Directories。
复制这个haha.h到程序目录中。 然后在头文件中加入了extern "C"_declspec (dllimport) int mmm(int n);
cpp文件中include "haha.h"
结果是运行后提示:c:\documents and settings\administrator\桌面\project\exmfcdll\haha.h(12) : warning C4273: 'mmm' : inconsistent dll linkage. dllexport assumed.
Linking...
ExMFCDLLDlg.obj : error LNK2001: unresolved external symbol _mmm
Debug/ExMFCDLL.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.ExMFCDLL.exe - 2 error(s), 1 warning(s)现在是还少了哪些引用啊,求高手帮忙啊。
贴上haha.h的代码:#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000_declspec(dllexport) int mmm(int n);
class haha
{
public:
int mmm(int n);
haha();
virtual ~haha();};
haha.cpp:#include "stdafx.h"
#include "haha.h"//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////haha::haha()
{}haha::~haha()
{}int haha::mmm(int n)
{
return n;
}
里面新建了一个haha的Class类, 类中新建了一个int mmm(int n)的成员方法,
已经在haha类头文件中加 _declspec(dllexport) int mmm(int n);生成与MFC程序(名ExMFCDLL)关联的DLL,已经把这个DLL放进debug中并设置好Directories。
复制这个haha.h到程序目录中。 然后在头文件中加入了extern "C"_declspec (dllimport) int mmm(int n);
cpp文件中include "haha.h"
结果是运行后提示:c:\documents and settings\administrator\桌面\project\exmfcdll\haha.h(12) : warning C4273: 'mmm' : inconsistent dll linkage. dllexport assumed.
Linking...
ExMFCDLLDlg.obj : error LNK2001: unresolved external symbol _mmm
Debug/ExMFCDLL.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.ExMFCDLL.exe - 2 error(s), 1 warning(s)现在是还少了哪些引用啊,求高手帮忙啊。
贴上haha.h的代码:#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000_declspec(dllexport) int mmm(int n);
class haha
{
public:
int mmm(int n);
haha();
virtual ~haha();};
haha.cpp:#include "stdafx.h"
#include "haha.h"//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////haha::haha()
{}haha::~haha()
{}int haha::mmm(int n)
{
return n;
}
_declspec(dllexport) int mmm(int n); //这是头文件定义的,cpp应该有个对应的定义。类的封装性,不允许直接调用类的函数,除非将它(封装性)破坏掉。
比如:
class haha
{
public:
static int mmm(int n); //加了个static
haha();
virtual ~haha();};
cpp的具体实现,你自己琢磨着办吧。
我在cpp中的mmm前加了static 运行不通过呀? 是改哪里呢