Hi all,
I'm trying to compile an example from MSDN showing how to read from the eventlog.
The compilation fails.
Here's the source code:
void DisplayEntries( ) { HANDLE h; EVENTLOGRECORD *pevlr; BYTE bBuffer[BUFFER_SIZE]; DWORD dwRead, dwNeeded, dwThisRecord;
// Open the Application event log. h = OpenEventLog( NULL, // use local computer "Application"); // source name if (h == NULL) { printf("Could not open the Application event log."); return; } pevlr = (EVENTLOGRECORD *) &bBuffer; // Get the record number of the oldest event log record. GetOldestEventLogRecord(h, &dwThisRecord); // Opening the event log positions the file pointer for this // handle at the beginning of the log. Read the event log records // sequentially until the last record has been read. while (ReadEventLog(h, // event log handle EVENTLOG_FORWARDS_READ | // reads forward EVENTLOG_SEQUENTIAL_READ, // sequential read 0, // ignored for sequential reads pevlr, // pointer to buffer BUFFER_SIZE, // size of buffer &dwRead, // number of bytes read &dwNeeded)) // bytes in next record { while (dwRead > 0) { // Print the record number, event identifier, type, // and source name. printf("%03d Event ID: 0x%08X Event type: ", dwThisRecord++, pevlr->EventID); switch(pevlr->EventType) { case EVENTLOG_ERROR_TYPE: printf("EVENTLOG_ERROR_TYPE\t "); break; case EVENTLOG_WARNING_TYPE: printf("EVENTLOG_WARNING_TYPE\t "); break; case EVENTLOG_INFORMATION_TYPE: printf("EVENTLOG_INFORMATION_TYPE "); break; case EVENTLOG_AUDIT_SUCCESS: printf("EVENTLOG_AUDIT_SUCCESS\t "); break; case EVENTLOG_AUDIT_FAILURE: printf("EVENTLOG_AUDIT_FAILURE\t "); break; default: printf("Unknown "); break; } printf("Event source: %s\n", (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD))); dwRead -= pevlr->Length; pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length); } pevlr = (EVENTLOGRECORD *) &bBuffer; } CloseEventLog(h);
}
The compile log:
Compiler: Default compiler Building Makefile: "H:\work\event\Makefile.win" Executing make clean rm -f main.o eventtest.exe
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"
gcc.exe main.o -o "eventtest.exe" -L"C:/Dev-Cpp/lib" -mwindows -lndis -ladvapi32 -lapi32
C:\Dev-Cpp\Bin..\lib\gcc-lib\mingw32\3.3.1........\mingw32\bin\ld.exe: cannot find -lapi32
make.exe: *** [eventtest.exe] Error 1
Execution terminated
The inclusion of the ndis, advapi32 and api32 is a vain attempt on my part to negotiate the error.
Help is welcomed.
Best regards /Lars.
gcc.exe main.o -o "eventtest.exe" -L"C:/Dev-Cpp/lib" -mwindows -ladvapi32
C:/Dev-Cpp/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
/Lars.
And in the FAQ ... sorry ...
It is a console application and as such should have a main().
Windows applications must have a WinMain().
My cut&pasted app had neither.
(With very red ears) /Lars.
Log in to post a comment.
Hi all,
I'm trying to compile an example from MSDN showing how to read from the eventlog.
The compilation fails.
Here's the source code:
include <windows.h>
include <stdio.h>
define BUFFER_SIZE 1024*64
void DisplayEntries( )
{
HANDLE h;
EVENTLOGRECORD *pevlr;
BYTE bBuffer[BUFFER_SIZE];
DWORD dwRead, dwNeeded, dwThisRecord;
}
The compile log:
Compiler: Default compiler
Building Makefile: "H:\work\event\Makefile.win"
Executing make clean
rm -f main.o eventtest.exe
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"
gcc.exe main.o -o "eventtest.exe" -L"C:/Dev-Cpp/lib" -mwindows -lndis -ladvapi32 -lapi32
C:\Dev-Cpp\Bin..\lib\gcc-lib\mingw32\3.3.1........\mingw32\bin\ld.exe: cannot find -lapi32
make.exe: *** [eventtest.exe] Error 1
Execution terminated
The inclusion of the ndis, advapi32 and api32 is a vain attempt on my part to negotiate the error.
Help is welcomed.
Best regards
/Lars.
Compiler: Default compiler
Building Makefile: "H:\work\event\Makefile.win"
Executing make clean
rm -f main.o eventtest.exe
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"
gcc.exe main.o -o "eventtest.exe" -L"C:/Dev-Cpp/lib" -mwindows -ladvapi32
C:/Dev-Cpp/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
make.exe: *** [eventtest.exe] Error 1
Execution terminated
/Lars.
And in the FAQ ... sorry ...
It is a console application and as such should have a main().
Windows applications must have a WinMain().
My cut&pasted app had neither.
(With very red ears)
/Lars.