0
我想创建一个动态库,并将其导入到我的主程序中。 但是我不能正确运行我的程序,因为我从LIB切换到DLL。链接DLL和类方法明确
这是我的DLL .h文件中:
class Connector
{
public:
Connector(std::string _apiKey,
std::string _masterCode,
std::string _masterSystem,
std::string _masterVersion,
int INTERNAL_PARAMETER = -1);
virtual ~Connector();
std::string query(std::string method,
std::map<std::string,
std::string> params);
[...]
}
这是我mainApp链接代码:
typedef std::string (CALLBACK* kcDLLFUNC_QUERY)(
std::string, std::map<std::string, std::string>, std::string);
HINSTANCE kcDLL = LoadLibrary(_T("Connect"));
kcDLLFUNC_QUERY kcDLLFUNC_query = (kcDLLFUNC_QUERY)GetProcAddress(kcDLL, "query");
std::map<std::string, std::string> params;
params["amount"] = "50";
std::string RES = kcDLLFUNC_query("de", params, "");
std::cout << RES << std::endl;
FreeLibrary(kcDLL);
没有忘记什么了吗?
我该如何切换DLL_API的定义?当我尝试它时,我得到一些未解析令牌 –
'DLL_API'因为它将被定义为DLL项目中的所有文件,并且不会为EXE项目中的文件定义。我忘了提到的一个步骤是EXE项目必须链接到DLL的项目。我将通过如何添加参考来更新我的答案。 – Andy
我试过了,效果很好!但我需要.lib文件来做到这一点。有没有.lib文件链接的方法? –