I'm trying to call the windows API GetWindowTextA. It outputs to a LPSTR which is a [*:0]u8. When I reference my buffer locally I get the error expected type '[*:0]u8', found '[]u8'. I'm sure this is a easy one to fix, but I'm still new at Zig and low level languages so I'm struggling to get this right. Here is the relevant pieces of code:
pub extern "user32" fn GetWindowTextA(
hWnd: HWND,
lptString: LPSTR,
nMaxCount: INT,
) callconv(.winapi) INT;
var windowHandle = GetTopWindow(null);
var windowText: [2048]u8 = undefined;
while (windowHandle) |handle| {
if (IsWindowVisible(handle) > 0) {
var titleLength = GetWindowTextA(handle, &windowText, windowText.len);
titleLength = if (titleLength > windowText.len) windowText.len else titleLength;
const len = std.math.cast(usize, titleLength) orelse @panic("Could not cast c_int to usize.");
std.debug.print("{s}\n", .{windowText[0..len]});
}
windowHandle = GetWindow(handle, 2);
}