| ... | @@ -1,5 +1,51 @@ | ... | @@ -1,5 +1,51 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| | 2 | const builtin = @import("builtin"); |
| | 3 | const w = std.os.windows; |
| 2 | | 4 | |
| 3 | pub fn main() !void { | 5 | pub 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 | } |
| 5 | } | 25 | } |
| | 26 | |
| | 27 | const HRSRC = *opaque {}; |
| | 28 | const HGLOBAL = *opaque {}; |
| | 29 | fn MAKEINTRESOURCEW(id: u16) [*:0]align(1) const w.WCHAR { |
| | 30 | return @ptrFromInt(id); |
| | 31 | } |
| | 32 | |
| | 33 | extern "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 | |
| | 39 | extern "kernel32" fn LoadResource( |
| | 40 | hModule: ?w.HMODULE, |
| | 41 | hResInfo: HRSRC, |
| | 42 | ) callconv(.winapi) ?HGLOBAL; |
| | 43 | |
| | 44 | extern "kernel32" fn LockResource( |
| | 45 | hResData: HGLOBAL, |
| | 46 | ) callconv(.winapi) ?w.LPVOID; |
| | 47 | |
| | 48 | extern "kernel32" fn SizeofResource( |
| | 49 | hModule: ?w.HMODULE, |
| | 50 | hResInfo: HRSRC, |
| | 51 | ) callconv(.winapi) w.DWORD; |