#pragma once
#ifndef testMfcDll_H
#define testMfcDll_H
class __declspec(dllexport) testMfcDll;
class testMfcDll
{
public:
testMfcDll(){};
virtual ~testMfcDll(){};
void sayHello();
CString &sayHelloWord();
void sayWhat(CString &);
CString strHello;
};
#endif
// testMfcDll.cpp : 定义 DLL 的初始化例程。
//
#include "stdafx.h"
#include "testMfcDll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
void testMfcDll::sayHello()
{
//这是win的MessageBox
MessageBox(NULL, _T("hello"), _T("提示"), MB_OK);
}
CString& testMfcDll::sayHelloWord()
{
strHello = _T("hello world");
return strHello;
}
void testMfcDll::sayWhat(CString &str)
{
if(str == _T("hello"))
{
str = _T("get way");
MessageBox(NULL, _T("get way"), _T("提示"), MB_OK);
}else
{
MessageBox(NULL, _T("hello"), _T("提示"), MB_OK);
}
}
调用代码
testMfcDll test;
test.sayHello();//只调用这个可以正常运行
CString str = _T("hello");
str = test.sayHelloWord();//这个编译不过
test.sayWhat(str);//这个编译不过
MessageBox(str);
错误信息
1>testADODlg.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall testMfcDll::sayWhat(class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > &)" (?sayWhat@testMfcDll@@QAEXAAV?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z),该符号在函数 xxx 中被引用
1>testADODlg.obj : error LNK2019: 无法解析的外部符号 "public: class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > & __thiscall testMfcDll::sayHelloWord(void)" (?sayHelloWord@testMfcDll@@QAEAAV?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@XZ),该符号在函数 xxx中被引用