错误: LNK1120: 5个未解析的外部符号
错误: LNK1120: 5个未解析的外部符号
我正在尝试获取我帖子中安装的应用程序的详细信息。但是,我遇到了以下错误:\n代码:\n
#include#include #include using namespace std; #ifdef _UNICODE #define tcout wcout #define tstring wstring #else #define tcout cout #define tstring string #endif tstring RegistryQueryValue(HKEY hKey, LPCTSTR szName) { tstring value; DWORD dwType; DWORD dwSize = 0; if (::RegQueryValueEx( hKey, // 键句柄 szName, // 项目名称 NULL, // 保留 &dwType, // 存储的数据类型 NULL, // 没有数据缓冲区 &dwSize // 需要的缓冲区大小 ) == ERROR_SUCCESS && dwSize > 0) { value.resize(dwSize); ::RegQueryValueEx( hKey, // 键句柄 szName, // 项目名称 NULL, // 保留 &dwType, // 存储的数据类型 (LPBYTE)&value[0], // 数据缓冲区 &dwSize // 可用的缓冲区大小 ); } return value; } void RegistryEnum() { HKEY hKey; LONG ret = ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, // 本地机器注册表 __TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"), // 卸载键 0, // 保留 KEY_READ, // 所需的访问权限 &hKey // 打开键的句柄 ); if (ret != ERROR_SUCCESS) return; DWORD dwIndex = 0; DWORD cbName = 1024; TCHAR szSubKeyName[1024]; while ((ret = ::RegEnumKeyEx( hKey, dwIndex, szSubKeyName, &cbName, NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS) { if (ret == ERROR_SUCCESS) { HKEY hItem; if (::RegOpenKeyEx(hKey, szSubKeyName, 0, KEY_READ, &hItem) != ERROR_SUCCESS) continue; tstring name = RegistryQueryValue(hItem, __TEXT("DisplayName")); tstring publisher = RegistryQueryValue(hItem, __TEXT("Publisher")); tstring version = RegistryQueryValue(hItem, __TEXT("DisplayVersion")); tstring location = RegistryQueryValue(hItem, __TEXT("InstallLocation")); if (!name.empty()) { tcout << name << endl; tcout << " - " << publisher << endl; tcout << " - " << version << endl; tcout << " - " << location << endl; tcout << endl; } ::RegCloseKey(hItem); } dwIndex++; cbName = 1024; } ::RegCloseKey(hKey); } void main(){ RegistryEnum(); }
\n错误信息:\n
\nLNK1120: 5 个未解析的外部符号\nLNK2019: 无法解析的外部符号 _imp_RegCloseKey@4 在函数 \"void __cdecl RegistryEnum(void)\" (?RegistryEnum@@YAXXZ) 中被引用\nLNK2019: 无法解析的外部符号 _imp_RegEnumKeyExW@32 在函数 \"void __cdecl RegistryEnum(void)\" (?RegistryEnum@@YAXXZ) 中被引用\nLNK2019: 无法解析的外部符号 _imp_RegOpenKeyExW@20 在函数 \"void __cdecl RegistryEnum(void)\" (?RegistryEnum@@YAXXZ) 中被引用\nLNK2019: 无法解析的外部符号 imp__RegQueryValueExW@24 在函数 \"class std::basic_string,class std::allocator > __cdecl RegistryQueryValue(struct HKEY *,wchar_t const *)\" (?RegistryQueryValue@@YA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@W@2@@std@@PAUHKEY_@@PB_W@Z) 中被引用\nLNK2019: 无法解析的外部符号 wWinMain@16 在函数 __tmainCRTStartup 中被引用\n
\n请问我应该如何解决这个问题?
(error: LNK1120: 5 unresolved externals)这个问题的出现的原因是没有链接到Advapi32.lib库。解决方法是需要手动添加Advapi32.lib库链接。
在使用Visual Studio 2013 Ultimate开发环境时,如果出现了(error: LNK1120: 5 unresolved externals)错误,可能是由于没有链接到Advapi32.lib库导致的。
解决这个问题的方法是在项目中手动添加Advapi32.lib库的链接。可以按照以下步骤进行操作:
1. 打开Visual Studio 2013 Ultimate。
2. 在解决方案资源管理器中找到你的项目。
3. 右键单击项目,选择“属性”。
4. 在属性窗口中,选择“链接器”选项卡。
5. 在“输入”下的“附加依赖项”中添加“Advapi32.lib”。
6. 点击“应用”按钮,然后点击“确定”按钮。
完成上述操作后,重新编译项目,应该就可以解决(error: LNK1120: 5 unresolved externals)这个问题了。
如果问题仍然存在,可以尝试从头开始创建一个新的项目,并在其中使用一些Reg*函数,然后尝试编译项目。这样可以确定是否是项目配置的问题导致的错误。
希望这篇文章对你解决(error: LNK1120: 5 unresolved externals)问题有所帮助。