在使用server.dll和client.exe的项目中,我dllexport从服务器dll编辑了一个服务器符号,而不是将其 dllimport编辑到客户端exe中.
仍然,应用程序链接,并启动,没有任何问题.是dllimport不需要的,那么???
细节:
我有这个'服务器'DLL:
// server.h
#ifdef SERVER_EXPORTS
#define SERVER_API __declspec(dllexport)
#else
#define SERVER_API // =====> not using dllimport!
#endif
class SERVER_API CServer {
static long s;
public:
CServer();
};
// server.cpp
CServer::CServer(){}
long CServer::s;
Run Code Online (Sandbox Code Playgroud)
这个客户端可执行文件
#include <server.h>
int main() {
CServer s;
}
Run Code Online (Sandbox Code Playgroud)
服务器命令行:
cl.exe /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL"
/D "SERVER_EXPORTS" /D "_UNICODE" /D "UNICODE" /D "_WINDLL"
/Gm /EHsc /RTC1 /MDd /Yu"stdafx.h"
/Fp"Debug\server.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb"
/W3 /nologo …Run Code Online (Sandbox Code Playgroud) 我有一个用C++编程的DLL,以及用Visual C++编写的exe.
我将dll中的函数声明为:
string __declspec( dllexport ) ConfigureHAT(T_STRING pathFile);
Run Code Online (Sandbox Code Playgroud)
在exe项目中,我包含了所有头文件和dll文件.
我在dll中调用该函数:
string ret = ConfigureHAT("file.txt");
Run Code Online (Sandbox Code Playgroud)
当编译可执行项目时,它会因下一个错误而失败:
1> HATdllTester.obj:错误LNK2028:未解析的令牌(0A000317)"class std :: basic_string,class std :: allocator> __cdecl ConfigureHAT(class std :: basic_string,class std :: allocator>)"(?ConfigureHAT @@ $ $ FYA?AV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ V12 @@ Z)在函数"private:void __clrcall HATdllTester :: mainWindow ::"中引用buttonConfigure_Click(类System :: Object ^,类System :: EventArgs ^)"(?buttonConfigure_Click @ mainWindow @ HATdllTester @@ $$ FA $ AAMXP $ AAVObject @ …