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文件鏈接的方法? –