SQLite Forum

WinRT build fixes
Login

WinRT build fixes

(1) By Steve Lhomme (robux4) on 2020-04-09 06:21:39 [source]

Hi,

Not sure if this is the right place as I did not way anywhere how to contribute the project, but I made a patch to fix the WinRT/UWP build.

Problem 1: SQLITE_OS_WINRT is used with a #if even when the value is not defined. Some compilers don't like that.

Problem 2: GetStdHandle/GetConsoleScreenBufferInfo/SetConsoleTextAttribute are forbidden APIs in UWP.

https://docs.microsoft.com/en-us/windows/console/getstdhandle https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo https://docs.microsoft.com/en-us/windows/console/setconsoletextattribute

Problem 3: DebugBreak is a forbidden API in UWP

https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-debugbreak

Here is the patch you can use freely:

--- sqlite/shell.c.uwp	2019-07-10 20:07:04.000000000 +0200
+++ sqlite/shell.c	2020-04-08 14:13:35.935077300 +0200
@@ -34,6 +34,9 @@
 /* This needs to come before any includes for MSVC compiler */
 #define _CRT_SECURE_NO_WARNINGS
 #endif
+#if !defined(SQLITE_OS_WINRT)
+# define SQLITE_OS_WINRT 0
+#endif
 
 /*
 ** Warning pragmas copied from msvc.h in the core.
@@ -18440,6 +18443,9 @@ static void main_init(ShellState *data)
 */
 #ifdef _WIN32
 static void printBold(const char *zText){
+#if SQLITE_OS_WINRT
+  OutputDebugStringA(zText);
+#else
   HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
   CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
   GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
@@ -18448,6 +18454,7 @@ static void printBold(const char *zText)
   );
   printf("%s", zText);
   SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
+#endif
 }
 #else
 static void printBold(const char *zText){
@@ -18511,7 +18518,9 @@ int SQLITE_CDECL wmain(int argc, wchar_t
       fgetc(stdin);
     }else{
 #if defined(_WIN32) || defined(WIN32)
+#if !SQLITE_OS_WINRT
       DebugBreak();
+#endif
 #elif defined(SIGTRAP)
       raise(SIGTRAP);
 #endif