authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-01-13 02:36:21-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-01-27 20:48:59+01:00
log1655a666d5695ac974e107233a90a75eebe5fc2f
tree475adbdf3eb0086c48ca61bf276c25b3ff15543e
parent29b7214027b0c9bddc4c67587ee75b4adcdab4f8

windows_resources standalone test: Load a resource and check its data

Just a potential way to catch regressions and to ensure the resources actually make it into the binary correctly.

2 files changed, 52 insertions(+), 3 deletions(-)

test/standalone/windows_resources/build.zig+5-2
......@@ -46,7 +46,10 @@ fn add(
4646 .gnu => .gnu,
4747 };
4848
49 _ = exe.getEmittedBin();
49 const exe_run_step = b.addRunArtifact(exe);
50 exe_run_step.skip_foreign_checks = true;
51 exe_run_step.expectStdErrEqual("");
52 exe_run_step.expectStdOutEqual("");
5053
51 test_step.dependOn(&exe.step);
54 test_step.dependOn(&exe_run_step.step);
5255}
test/standalone/windows_resources/main.zig+47-1
......@@ -1,5 +1,51 @@
11const std = @import("std");
2const builtin = @import("builtin");
3const w = std.os.windows;
24
35pub fn main() !void {
4 std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
6 if (builtin.os.tag == .windows) {
7 const name = std.unicode.wtf8ToWtf16LeStringLiteral("FOO");
8 const RT_RCDATA = MAKEINTRESOURCEW(10);
9 const handle = FindResourceW(null, name, RT_RCDATA) orelse {
10 std.debug.print("unable to find resource: {t}\n", .{w.GetLastError()});
11 return error.FailedToLoadResource;
12 };
13 const res = LoadResource(null, handle) orelse {
14 std.debug.print("unable to load resource: {t}\n", .{w.GetLastError()});
15 return error.FailedToLoadResource;
16 };
17 const data_ptr = LockResource(res) orelse {
18 std.debug.print("unable to lock resource: {t}\n", .{w.GetLastError()});
19 return error.FailedToLoadResource;
20 };
21 const size = SizeofResource(null, handle);
22 const data = @as([*]const u8, @ptrCast(data_ptr))[0..size];
23 try std.testing.expectEqualSlices(u8, "foo", data);
24 }
525}
26
27const HRSRC = *opaque {};
28const HGLOBAL = *opaque {};
29fn MAKEINTRESOURCEW(id: u16) [*:0]align(1) const w.WCHAR {
30 return @ptrFromInt(id);
31}
32
33extern "kernel32" fn FindResourceW(
34 hModule: ?w.HMODULE,
35 lpName: [*:0]align(1) const w.WCHAR,
36 lpType: [*:0]align(1) const w.WCHAR,
37) callconv(.winapi) ?HRSRC;
38
39extern "kernel32" fn LoadResource(
40 hModule: ?w.HMODULE,
41 hResInfo: HRSRC,
42) callconv(.winapi) ?HGLOBAL;
43
44extern "kernel32" fn LockResource(
45 hResData: HGLOBAL,
46) callconv(.winapi) ?w.LPVOID;
47
48extern "kernel32" fn SizeofResource(
49 hModule: ?w.HMODULE,
50 hResInfo: HRSRC,
51) callconv(.winapi) w.DWORD;