builtin: windows definitions

This commit is contained in:
Alexander Medvednikov 2023-10-15 07:43:52 +03:00
parent 1efdb88c55
commit c947c140ee
3 changed files with 25 additions and 5 deletions

View File

@ -7,7 +7,25 @@ module builtin
// g_original_codepage - used to restore the original windows console code page when exiting
__global g_original_codepage = u32(0)
type C.BOOL = bool
pub type C.BOOL = bool
pub struct C.HINSTANCE {}
pub struct C.HICON {}
pub struct C.HCURSOR {}
pub struct C.HCURSOR {}
pub struct C.HBRUSH {}
pub struct C.HWND {}
pub struct C.HGLOBAL {}
pub struct C.HANDLE {}
pub struct C.LRESULT {}
// utf8 to stdout needs C.SetConsoleOutputCP(cp_utf8)
fn C.GetConsoleOutputCP() u32

View File

@ -110,7 +110,7 @@ fn new_clipboard() &Clipboard {
// check_availability returns true if the clipboard is ready to be used.
pub fn (cb &Clipboard) check_availability() bool {
return cb.hwnd != C.HWND(C.NULL)
return cb.hwnd != unsafe { nil }
}
// has_ownership returns true if the contents of
@ -143,7 +143,7 @@ fn to_wide(text string) C.HGLOBAL {
len_required := C.MultiByteToWideChar(clipboard.cp_utf8, C.MB_ERR_INVALID_CHARS, text.str,
text.len + 1, C.NULL, 0)
buf := C.GlobalAlloc(C.GMEM_MOVEABLE, i64(sizeof(u16)) * len_required)
if buf != C.HGLOBAL(C.NULL) {
if buf != unsafe { nil } {
mut locked := &u16(C.GlobalLock(buf))
C.MultiByteToWideChar(clipboard.cp_utf8, C.MB_ERR_INVALID_CHARS, text.str, text.len + 1,
locked, len_required)
@ -166,7 +166,7 @@ pub fn (mut cb Clipboard) set_text(text string) bool {
} else {
// EmptyClipboard must be called to properly update clipboard ownership
C.EmptyClipboard()
if C.SetClipboardData(C.CF_UNICODETEXT, buf) == C.HANDLE(C.NULL) {
if C.SetClipboardData(C.CF_UNICODETEXT, buf) == unsafe { nil } {
println('SetClipboardData: Failed.')
C.CloseClipboard()
C.GlobalFree(buf)
@ -187,7 +187,7 @@ pub fn (mut cb Clipboard) get_text() string {
return ''
}
h_data := C.GetClipboardData(C.CF_UNICODETEXT)
if h_data == C.HANDLE(C.NULL) {
if h_data == unsafe { nil } {
C.CloseClipboard()
return ''
}

View File

@ -11,6 +11,8 @@ $if gcboehm ? {
#flag -l ws2_32 -l crypt32 -l secur32 -l user32
#include "vschannel.c"
struct C.TlsContext {}
fn C.new_tls_context() C.TlsContext
fn (req &Request) ssl_do(port int, method Method, host_name string, path string) !Response {