fixed calling convention

This commit is contained in:
2026-03-06 12:52:44 -06:00
parent 5d9920868c
commit ed110c8c1a
4 changed files with 37 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
#ifndef PLATFORM_INCLUDED
#define PLATFORM_INCLUDED
extern int plat_main(void);
extern int plat_main(int argc, char **argv);
#endif // platform.h

View File

@@ -5,7 +5,9 @@
#include "../include/platform.h"
int plat_main(void) {
int plat_main(int argc, char **argv) {
(void) argc;
(void) argv;
Display *display = XOpenDisplay(NULL);
if (!display) {
fprintf(stderr, "Cannot open display\n");

View File

@@ -14,44 +14,50 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI plat_main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
int plat_main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 1. Register the window class
WNDCLASS wc = {};
HINSTANCE hInstance = GetModuleHandle(NULL);
const char CLASS_NAME[] = "MyWindowClass";
// Step 1: Register the window class
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = "MyWindowClass";
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
RegisterClass(&wc);
if (!RegisterClass(&wc)) {
MessageBox(NULL, "Failed to register window class!", "Error", MB_OK | MB_ICONERROR);
return;
}
// 2. Create the window
// Step 2: Create the window
HWND hwnd = CreateWindowEx(
0, // Extended style
"MyWindowClass", // Class name
"Hello, Win32!", // Window title
WS_OVERLAPPEDWINDOW, // Style (title bar, border, min/max/close buttons)
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, // x, y, width, height
0, // Optional window styles
CLASS_NAME, // Window class
"My Win32 Window", // Window title
WS_OVERLAPPEDWINDOW, // Window style
CW_USEDEFAULT, CW_USEDEFAULT, 500, 400, // x, y, width, height
NULL, // Parent window
NULL, // Menu
hInstance,
NULL
hInstance, // Instance handle
NULL // Additional application data
);
if (!hwnd) return -1;
if (!hwnd) {
MessageBox(NULL, "Failed to create window!", "Error", MB_OK | MB_ICONERROR);
return;
}
// 3. Show the window
ShowWindow(hwnd, nCmdShow);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
// 4. Message loop
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0))
{
// Step 3: Message loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}

View File

@@ -1,6 +1,6 @@
#define DEBUG
#include "../include/platform.h"
int main(void){
int main(int argc, char **argv){
return plat_main();
return plat_main(argc,argv);
}