diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e26c4ff47..314674842d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -796,6 +796,9 @@ if(MSVC) set(EXE_CFLAGS "${EXE_CFLAGS}") else() set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") + if(MINGW) + set(EXE_CFLAGS "${EXE_CFLAGS} -D__USE_MINGW_ANSI_STDIO -Wno-pedantic-ms-format") + endif() endif() set(BLAKE_CFLAGS "-std=c99") diff --git a/example/hello_world/hello_windows.zig b/example/hello_world/hello_windows.zig index f55db2edeb..8016c3c490 100644 --- a/example/hello_world/hello_windows.zig +++ b/example/hello_world/hello_windows.zig @@ -1,5 +1,7 @@ use @import("std").os.windows; +extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int; + export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT { _ = MessageBoxA(null, c"hello", c"title", 0); return 0; diff --git a/src/os.cpp b/src/os.cpp index 431f7d16b4..6c620fae2e 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -23,6 +23,14 @@ #define WIN32_LEAN_AND_MEAN #endif +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x600 +#endif + +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06000000 +#endif + #include #include #include @@ -1634,16 +1642,16 @@ static Optional Utf16LeIterator_nextCodepoint(Utf16LeIterator *it) { if (it->bytes[it->i] == 0 && it->bytes[it->i + 1] == 0) return {}; uint32_t c0 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8); - if (c0 & ~((uint32_t)0x03ff) == 0xd800) { + if ((c0 & ~((uint32_t)0x03ff)) == 0xd800) { // surrogate pair it->i += 2; assert(it->bytes[it->i] != 0 || it->bytes[it->i + 1] != 0); uint32_t c1 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8); - assert(c1 & ~((uint32_t)0x03ff) == 0xdc00); + assert((c1 & ~((uint32_t)0x03ff)) == 0xdc00); it->i += 2; return Optional::some(0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff))); } else { - assert(c0 & ~((uint32_t)0x03ff) != 0xdc00); + assert((c0 & ~((uint32_t)0x03ff)) != 0xdc00); it->i += 2; return Optional::some(c0); } @@ -1714,7 +1722,7 @@ static void utf16le_ptr_to_utf8(Buf *out, WCHAR *utf16le) { // Ported from std.os.getAppDataDir Error os_get_app_data_dir(Buf *out_path, const char *appname) { #if defined(ZIG_OS_WINDOWS) - Error err; + // Error err; WCHAR *dir_path_ptr; switch (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &dir_path_ptr)) { case S_OK: @@ -1928,7 +1936,8 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { FILETIME last_write_time; if (!GetFileTime(file, nullptr, nullptr, &last_write_time)) return ErrorUnexpected; - mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32); + // mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32); + mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; mtime->nsec = 0; return ErrorNone; #elif defined(ZIG_OS_LINUX) @@ -2007,11 +2016,12 @@ Error os_file_read_all(OsFile file, Buf *contents) { Error os_file_overwrite(OsFile file, Buf *contents) { #if defined(ZIG_OS_WINDOWS) + DWORD bytes_written; if (SetFilePointer(file, 0, nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER) return ErrorFileSystem; if (!SetEndOfFile(file)) return ErrorFileSystem; - if (!WriteFile(file, buf_ptr(contents), buf_len(contents), nullptr, nullptr)) + if (!WriteFile(file, buf_ptr(contents), buf_len(contents), &bytes_written, nullptr)) return ErrorFileSystem; return ErrorNone; #else diff --git a/src/windows_com.hpp b/src/windows_com.hpp index 4c807218c0..f9833e0912 100644 --- a/src/windows_com.hpp +++ b/src/windows_com.hpp @@ -28,6 +28,9 @@ #include #include +// Standard headers +#include + // COM support header files #include