Error: main.obj: -1: error: LNK2019: link to unresolved external symbol __imp__RegOpenKeyExW @ 20 in the _main function What could be wrong? MSVC2015 compiler 32, everything works on mingw, but I need the MSVC compiler here's the code:

#include "mainwindow.h" #include <QApplication> #include "shobjidl.h" #include "windows.h" #include <QStringList> #include <QDebug> enum HKEY_LIST { HK_CLASSES_ROOT=0x80000000, HK_CURRENT_USER=0x80000001, HK_LOCAL_MACHINE=0x80000002, HK_USERS=0x80000003, HK_PERFORMANCE_DATA=0x80000004, HK_CURRENT_CONFIG=0x80000005 }; int main(int argc, char *argv[]) { QApplication a(argc, argv); // QString myValue; HKEY hKey; LPCWSTR val=L"WallPaper"; LPCWSTR path=L"Control panel\\Desktop"; HKEY_LIST list =HKEY_LIST::HK_CURRENT_USER; if(RegOpenKeyEx((HKEY)list,path,0,KEY_READ,&hKey)==ERROR_SUCCESS) { DWORD dwSize = 512; wchar_t lszValue[512]; bool noError=RegQueryValueEx(hKey,val,NULL,NULL,(LPBYTE)lszValue,&dwSize)==ERROR_SUCCESS; //RegCloseKey(hKey); if(noError) { QString outp = QString::fromWCharArray(lszValue); qDebug() <<"outp=" <<outp; } } MainWindow w; w.show(); return a.exec(); } 

1 answer 1

An error of the form “Link to an unresolved external symbol __imp__ имя @ число ” means that you have not connected a system static library containing information on how you can import the function имя .

In your case, this is the RegOpenKeyExW() function.

First you need to know exactly which static library we need. To do this, open the MSDN documentation for the desired function (without the suffixes A and W ), look for the section “Requirements” at the bottom, and in it the table with the field “Library”:

RegOpenKeyEx () function documentation

Now you need to add the library to the project properties.

  1. In Visual Studio, you need the Linker> Input> Additional Dependencies parameter:

    How to open project properties How to get to the field Additional Dependencies

    The name of the library can be added at least to the beginning, at least to the end. At the same time, it should begin with a small letter (despite the fact that in MSDN the first letter is for some reason large) and separated from the other names by a semicolon.

  2. In Qt Creator with the qmake build system, you need to add a line of the form LIBS += -l имя project file ( *.pro ), where имя is the name of the required static library, starting with a small letter and without the .lib extension.

  • Yes, I added LIBS + = -advapi32 The truth is that this Warning resulted in the same error: -1: warning: LNK4044: unrecognized parameter "/ advapi32"; ignored - Madoka Magica
  • @MadokaMagica, LIBS + = - l advapi32. You l (small L) before the library name missed. - ߊߚߤߘ
  • It still does not work, with the same error but the library is connected. ATP - Madoka Magica
  • @MadokaMagica, in the “Compile Output” panel there should be a printed long command line with all compiler parameters (starts with g++ ... , here's an example: ics.com/sites/default/files/pictures/snapshot25.png (at the bottom of the program window) ). Copy it here, please. - Jan
  • Everything worked, thank you very much, I don `t know, it was probably in my carelessness that I wrote something wrong there. I cleaned the project rebuilt it seems to work. - Madoka Magica