I first had troubles creating a Window, as the window wouldn't show, then I checked for errors using GetLastError()
function, and it printed error code 126 which means module not found according to MSDN (This usually appears when loading DLLs, but I don't do any of that).
I am using GCC compiler.
Help would be appreciated.
This is the code:
#include <stdio.h>
#include <Windows.h>
WNDCLASSEXA myWindowsClass = {};
LRESULT myMainProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
void setDefaultClassParameters(HINSTANCE hInstance);
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
printf("ERROR CODE: %i\n", GetLastError()); // Prints 126 Error
SetLastError((DWORD)0);
printf("ERROR CODE: %i\n", GetLastError()); // Prints 0
setDefaultClassParameters(hInstance);
RegisterClassExA(&myWindowsClass);
CreateWindowExA(
WS_EX_OVERLAPPEDWINDOW,
"MY CLASS NAME",
"MY WINDOW TITLE",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
printf("ERROR CODE: %i\n", GetLastError()); // Prints 126 Error
}
void setDefaultClassParameters(HINSTANCE hInstance){
myWindowsClass.cbSize = sizeof(WNDCLASSEX);
myWindowsClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
myWindowsClass.lpfnWndProc = (WNDPROC) myMainProc;
myWindowsClass.cbClsExtra = 0;
myWindowsClass.cbWndExtra = 0;
myWindowsClass.hInstance = hInstance;
myWindowsClass.hIcon = NULL;
myWindowsClass.hCursor = NULL;
myWindowsClass.hbrBackground = NULL;
myWindowsClass.lpszMenuName = NULL;
myWindowsClass.lpszClassName = "MY CLASS NAME";
myWindowsClass.hIconSm = NULL;
}
GetLastError
unless your last operation actually failed. – Some programmer dude Dec 7 '20 at 11:06SetLastError()
to 0 but then I usedRegisterClass()
function and it reset the error again to 126 implying that I have the problem some where in my program. Edit: Also when I tried to create a window that failed too. – Khalid Al Hajri Dec 7 '20 at 11:11CreateWindowExA
returns before checkingGetLastError
. Besides, you need to store the returned value as it's your window handle. – Some programmer dude Dec 7 '20 at 12:47