Missing Windows API functions

I noticed in std.os.windows.kernel32 there are functions to get/set the output codepage, but not the input codepage.

I had to add this to make my program work:

pub const GetConsoleOutputCP = windows.kernel32.GetConsoleOutputCP;
pub const SetConsoleOutputCP = windows.kernel32.SetConsoleOutputCP;

pub extern "kernel32" fn GetConsoleCP() callconv(.winapi) windows.UINT;

pub extern "kernel32" fn SetConsoleCP(
    wCodePageID: windows.UINT,
) callconv(.winapi) windows.BOOL;


const std = @import("std");
const windows = std.os.windows;

and I call them like this

    // ensure console input/output is UTF-8
    const utf8_codepage: c_uint = 65001;
    if (winApi.SetConsoleOutputCP(utf8_codepage) == 0) return winApi.lastError();
    if (winApi.SetConsoleCP(utf8_codepage) == 0) return winApi.lastError();

Or am I supposed to do it in a different way?

1 Like

What you’re doing seems fine to me.

Relevant issues for understanding the policy around os.windows bindings in the standard library:

1 Like

Thanks. So basically

is the way to go for Windows.

Probably, but I personally haven’t really minded manually writing out the bindings I need; it tends to double as a way to ensure I understand how to use the API.

1 Like

I’ll probably do the same since it’s the only function missing right now, not worth adding a dependency. Thanks

1 Like