动态链接库导出类报错_declspec(dllexport)error LNK2019: unresolved external symbol

ec06cumt ec06cumt 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用的是VS2010,想导出类,从而使用其中方法,方法也是public类型,在MFC中button事件中,引用类方法,却发现编译不通过,
我知道是链接的原因,但是网上搜索了半天都没有解决,有说是字符编码,在properties中改成No-set,没有用。
现在的字符编码都是Use Multi-Byte Character Set。
被导出类的字符编码也是Use Multi-Byte Character Set。还是没有用。



//DllPlus.h
#ifdef Dll_API
#else
#define Dll_API _declspec(dllimport)
#endif

Dll_API int add(int a,int b);
Dll_API int subtract(int a,int b);

class Dll_API PointObject
{
public:
void output(int x,int y);
};

//DllPlus.cpp

#define Dll_API _declspec(dllexport)
#include "DllPlus.h"
#include <Windows.h>
#include <iostream>

int add(int x,int y)
{
return x + y;
}

int subtract(int x,int y)
{
return x - y;
}
//在窗口上输出一字符串。
void output(int x,int y)
{
HWND hwnd = GetForegroundWindow();
HDC hdc = GetDC(hwnd);
char buf[20];
memset(buf,0,20);
sprintf(buf,"x=%d,y=%d",x,y);
TextOut(hdc,0,0,buf,strlen(buf));
ReleaseDC(hwnd,hdc);
}


//在MFC中的button事件中的代码:


#include "stdafx.h"
#include "DllTest.h"
#include "DllTestDlg.h"
#include "afxdialogex.h"
#include "..\..\DllPlus\DllPlus\DllPlus.h"

...


void CDllTestDlg::OnBnClickedButtonClass()
{
PointObject pt;
pt.output(3,5);
}




错误信息:

1>DllTestDlg.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall PointObject::output(int,int)" (__imp_?output@PointObject@@QAEXHH@Z) referenced in function "public: void __thiscall CDllTestDlg::OnBnClickedButtonClass(void)" (?OnBnClickedButtonClass@CDllTestDlg@@QAEXXZ)
1>E:\MFCWorkSpace\DllTest\Debug\DllTest.exe : fatal error LNK1120: 1 unresolved externals

不知道我的引用正不正确。要是不正确应该怎样引用啊?谢谢啊。
...全文
评论 7
收藏 已收藏
分享
返回顶部
ec06cumt
进程/线程/DLL 15,466 成员 49,169 内容