aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-10-15 19:37:55 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-10-15 19:37:55 -0700
commitd87bd3d8afc883853958389fcf4c65826426769b (patch)
treee081338028a98565fc44bd77c45bf90a3e1d862e /lib/std/start.zig
parentc7c38e72793df53e6582b6f8b501e18314ab07e9 (diff)
downloadzig-d87bd3d8afc883853958389fcf4c65826426769b.tar.gz
zig-d87bd3d8afc883853958389fcf4c65826426769b.zip
fixups regarding windows wide strings
* remove GetModuleHandleA from kernel32.zig. use of A functions considered harmful. * make it a compile error to expose WinMain instead of wWinMain. same thing. * start code declares wWinMainCRTStartup instead of WinMainCRTStartup when it has the choice.
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig38
1 files changed, 8 insertions, 30 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index e09f1be765..cb838fef34 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -29,11 +29,11 @@ comptime {
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
!@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
{
- @export(WinStartup, .{ .name = "WinMainCRTStartup" });
+ @export(WinStartup, .{ .name = "wWinMainCRTStartup" });
} else if (@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
!@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
{
- @export(WinMainCRTStartup, .{ .name = "WinMainCRTStartup" });
+ @compileError("WinMain not supported; declare wWinMain or main instead");
} else if (@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup") and
!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup"))
{
@@ -162,18 +162,6 @@ fn WinStartup() callconv(.Stdcall) noreturn {
std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain(u8, callMain));
}
-fn WinMainCRTStartup() callconv(.Stdcall) noreturn {
- @setAlignStack(16);
- if (!builtin.single_threaded) {
- _ = @import("start_windows_tls.zig");
- }
-
- std.debug.maybeEnableSegfaultHandler();
-
- const result = initEventLoopAndCallMain(std.os.windows.INT, callWinMain);
- std.os.windows.kernel32.ExitProcess(@bitCast(std.os.windows.UINT, result));
-}
-
fn wWinMainCRTStartup() callconv(.Stdcall) noreturn {
@setAlignStack(16);
if (!builtin.single_threaded) {
@@ -182,7 +170,7 @@ fn wWinMainCRTStartup() callconv(.Stdcall) noreturn {
std.debug.maybeEnableSegfaultHandler();
- const result = initEventLoopAndCallMain(std.os.windows.INT, callWWinMain);
+ const result = initEventLoopAndCallMain(std.os.windows.INT, call_wWinMain);
std.os.windows.kernel32.ExitProcess(@bitCast(std.os.windows.UINT, result));
}
@@ -266,7 +254,7 @@ inline fn initEventLoopAndCallMain(comptime Out: type, comptime mainFunc: fn ()
var result: u8 = undefined;
var frame: @Frame(callMainAsync) = undefined;
- _ = @asyncCall(&frame, &result, callMainAsync, .{u8, mainFunc, loop});
+ _ = @asyncCall(&frame, &result, callMainAsync, .{ u8, mainFunc, loop });
loop.run();
return result;
}
@@ -323,24 +311,14 @@ pub fn callMain() u8 {
}
}
-pub fn callWinMain() std.os.windows.INT {
- const hInstance = std.os.windows.kernel32.GetModuleHandleA(null);
- const lpCmdLine = std.os.windows.kernel32.GetCommandLineA();
-
- // There's no (documented) way to get the nCmdShow parameter, so we're
- // using this fairly standard default.
- const nCmdShow = std.os.windows.user32.SW_SHOW;
-
- return root.WinMain(hInstance, null, lpCmdLine, nCmdShow);
-}
-
-pub fn callWWinMain() std.os.windows.INT {
- const hInstance = std.os.windows.kernel32.GetModuleHandleA(null);
+pub fn call_wWinMain() std.os.windows.INT {
+ const hInstance = @ptrCast(std.os.windows.HINSTANCE, std.os.windows.kernel32.GetModuleHandleW(null).?);
+ const hPrevInstance: ?std.os.windows.HINSTANCE = null; // MSDN: "This parameter is always NULL"
const lpCmdLine = std.os.windows.kernel32.GetCommandLineW();
// There's no (documented) way to get the nCmdShow parameter, so we're
// using this fairly standard default.
const nCmdShow = std.os.windows.user32.SW_SHOW;
- return root.wWinMain(hInstance, null, lpCmdLine, nCmdShow);
+ return root.wWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}