I need to use the Windows Event Log functionality. To access the function of this API, you need to add dll to the project. I added the following to the .pro file:

LIBS += -lws2_32 \ c:/windows/System32/wevtapi.dll \ c:/Windows/System32/kernel32.dll \ 

Then, just in case, added wevtapi.h and #pragma comment(lib, "Wevtapi.lib") wherever necessary.

But MinGW does not see the functions and types in the focus:

 EvtOpenChannelEnum EvtNextChannelPath PEVT_VARIANT 

Gives an error message

'EvtOpenChannelEnum' hChannels = EvtOpenChannelEnum (NULL, 0);

What am I doing wrong?

code:

 #include <QCoreApplication> #include <windows.h> #include <sddl.h> #include <stdio.h> #include <winevt.h> #include <QCoreApplication> #include <winsock2.h> #include <windows.h> #include <sddl.h> #include <stdio.h> #include <winevt.h> #include <iostream> #include <string> #include <vector> #pragma comment(lib, "Wevtapi.lib") int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); EVT_HANDLE hChannels = NULL; hChannels = EvtOpenChannelEnum(NULL, 0); return a.exec(); } 

.pro

 QT += core QT -= gui LIBS += -lws2_32 \ c:/windows/System32/wevtapi.dll \ c:/Windows/System32/kernel32.dll \ c:/Windows/System32/shlwapi.dll LIBS += -lws2_32 -lkernel32 -lwevtapi -lshlwapi CONFIG += c++11 TARGET = untitled7 CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp 
  • one
    LIBS += -lkernel32 -lwevtapi - user194374
  • It did not help, everything does not see it - Nikola Krivosheya
  • Try #include <WinEvt.h> . - user194374
  • As I wrote above I tried it - it did not help - Nikola Krivosheya
  • 1) You never wrote that you tried WinEvt.h . 2) In this case, we need a minimal compiled example. - user194374

1 answer 1

The functions and types you need are declared in the header file winevt.h . However, they are "wrapped" in #if (_WIN32_WINNT >= 0x0600) . A value of 0x0600 means that they are only available on Windows Vista and above. Therefore it is necessary to define the constant _WIN32_WINNT before all included files. Then the code will look like this:

 #define _WIN32_WINNT 0x0600 #include <QCoreApplication> #include <windows.h> #include <winevt.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); EVT_HANDLE hChannels = NULL; hChannels = EvtOpenChannelEnum(NULL, 0); return a.exec(); } 

However, you can not "litter" the source texts with such definitions and add the following line to the .pro file:

 DEFINES += _WIN32_WINNT=0x0600 

Further, the required functions are implemented in the dynamic library (DLL) wevtapi , so you need to explicitly tell the linker to use it by adding the following to the same .pro file:

 LIBS += -lwevtapi 

Now the linker will also use the file libwevtapi.a when building the .exe file of the project, which says that the functions are in the wevtapi.dll library. Thus, the linker will add information about the need to connect this library to the executable file.