| ... | @@ -29,11 +29,11 @@ comptime { | ... | @@ -29,11 +29,11 @@ comptime { |
| 29 | if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and | 29 | if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and |
| 30 | !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup")) | 30 | !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup")) |
| 31 | { | 31 | { |
| 32 | @export(WinStartup, .{ .name = "WinMainCRTStartup" }); | 32 | @export(WinStartup, .{ .name = "wWinMainCRTStartup" }); |
| 33 | } else if (@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and | 33 | } else if (@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and |
| 34 | !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup")) | 34 | !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup")) |
| 35 | { | 35 | { |
| 36 | @export(WinMainCRTStartup, .{ .name = "WinMainCRTStartup" }); | 36 | @compileError("WinMain not supported; declare wWinMain or main instead"); |
| 37 | } else if (@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup") and | 37 | } else if (@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup") and |
| 38 | !@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) | 38 | !@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) |
| 39 | { | 39 | { |
| ... | @@ -162,18 +162,6 @@ fn WinStartup() callconv(.Stdcall) noreturn { | ... | @@ -162,18 +162,6 @@ fn WinStartup() callconv(.Stdcall) noreturn { |
| 162 | std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain(u8, callMain)); | 162 | std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain(u8, callMain)); |
| 163 | } | 163 | } |
| 164 | | 164 | |
| 165 | fn WinMainCRTStartup() callconv(.Stdcall) noreturn { | | |
| 166 | @setAlignStack(16); | | |
| 167 | if (!builtin.single_threaded) { | | |
| 168 | _ = @import("start_windows_tls.zig"); | | |
| 169 | } | | |
| 170 | | | |
| 171 | std.debug.maybeEnableSegfaultHandler(); | | |
| 172 | | | |
| 173 | const result = initEventLoopAndCallMain(std.os.windows.INT, callWinMain); | | |
| 174 | std.os.windows.kernel32.ExitProcess(@bitCast(std.os.windows.UINT, result)); | | |
| 175 | } | | |
| 176 | | | |
| 177 | fn wWinMainCRTStartup() callconv(.Stdcall) noreturn { | 165 | fn wWinMainCRTStartup() callconv(.Stdcall) noreturn { |
| 178 | @setAlignStack(16); | 166 | @setAlignStack(16); |
| 179 | if (!builtin.single_threaded) { | 167 | if (!builtin.single_threaded) { |
| ... | @@ -182,7 +170,7 @@ fn wWinMainCRTStartup() callconv(.Stdcall) noreturn { | ... | @@ -182,7 +170,7 @@ fn wWinMainCRTStartup() callconv(.Stdcall) noreturn { |
| 182 | | 170 | |
| 183 | std.debug.maybeEnableSegfaultHandler(); | 171 | std.debug.maybeEnableSegfaultHandler(); |
| 184 | | 172 | |
| 185 | const result = initEventLoopAndCallMain(std.os.windows.INT, callWWinMain); | 173 | const result = initEventLoopAndCallMain(std.os.windows.INT, call_wWinMain); |
| 186 | std.os.windows.kernel32.ExitProcess(@bitCast(std.os.windows.UINT, result)); | 174 | std.os.windows.kernel32.ExitProcess(@bitCast(std.os.windows.UINT, result)); |
| 187 | } | 175 | } |
| 188 | | 176 | |
| ... | @@ -266,7 +254,7 @@ inline fn initEventLoopAndCallMain(comptime Out: type, comptime mainFunc: fn () | ... | @@ -266,7 +254,7 @@ inline fn initEventLoopAndCallMain(comptime Out: type, comptime mainFunc: fn () |
| 266 | | 254 | |
| 267 | var result: u8 = undefined; | 255 | var result: u8 = undefined; |
| 268 | var frame: @Frame(callMainAsync) = undefined; | 256 | var frame: @Frame(callMainAsync) = undefined; |
| 269 | _ = @asyncCall(&frame, &result, callMainAsync, .{u8, mainFunc, loop}); | 257 | _ = @asyncCall(&frame, &result, callMainAsync, .{ u8, mainFunc, loop }); |
| 270 | loop.run(); | 258 | loop.run(); |
| 271 | return result; | 259 | return result; |
| 272 | } | 260 | } |
| ... | @@ -323,24 +311,14 @@ pub fn callMain() u8 { | ... | @@ -323,24 +311,14 @@ pub fn callMain() u8 { |
| 323 | } | 311 | } |
| 324 | } | 312 | } |
| 325 | | 313 | |
| 326 | pub fn callWinMain() std.os.windows.INT { | 314 | pub fn call_wWinMain() std.os.windows.INT { |
| 327 | const hInstance = std.os.windows.kernel32.GetModuleHandleA(null); | 315 | const hInstance = @ptrCast(std.os.windows.HINSTANCE, std.os.windows.kernel32.GetModuleHandleW(null).?); |
| 328 | const lpCmdLine = std.os.windows.kernel32.GetCommandLineA(); | 316 | const hPrevInstance: ?std.os.windows.HINSTANCE = null; // MSDN: "This parameter is always NULL" |
| 329 | | | |
| 330 | // There's no (documented) way to get the nCmdShow parameter, so we're | | |
| 331 | // using this fairly standard default. | | |
| 332 | const nCmdShow = std.os.windows.user32.SW_SHOW; | | |
| 333 | | | |
| 334 | return root.WinMain(hInstance, null, lpCmdLine, nCmdShow); | | |
| 335 | } | | |
| 336 | | | |
| 337 | pub fn callWWinMain() std.os.windows.INT { | | |
| 338 | const hInstance = std.os.windows.kernel32.GetModuleHandleA(null); | | |
| 339 | const lpCmdLine = std.os.windows.kernel32.GetCommandLineW(); | 317 | const lpCmdLine = std.os.windows.kernel32.GetCommandLineW(); |
| 340 | | 318 | |
| 341 | // There's no (documented) way to get the nCmdShow parameter, so we're | 319 | // There's no (documented) way to get the nCmdShow parameter, so we're |
| 342 | // using this fairly standard default. | 320 | // using this fairly standard default. |
| 343 | const nCmdShow = std.os.windows.user32.SW_SHOW; | 321 | const nCmdShow = std.os.windows.user32.SW_SHOW; |
| 344 | | 322 | |
| 345 | return root.wWinMain(hInstance, null, lpCmdLine, nCmdShow); | 323 | return root.wWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow); |
| 346 | } | 324 | } |