diff --git a/include/share/windows_unicode_filenames.h b/include/share/windows_unicode_filenames.h
index 7e196bf..a2f0bc0 100644
--- a/include/share/windows_unicode_filenames.h
+++ b/include/share/windows_unicode_filenames.h
@@ -55,9 +55,11 @@ int flac_internal_utime_utf8(const char *filename, struct utimbuf *times);
 int flac_internal_unlink_utf8(const char *filename);
 int flac_internal_rename_utf8(const char *oldname, const char *newname);
 
+#ifdef FLAC__COMPAT_USE_WINAPI
 #include <windows.h>
 HANDLE WINAPI flac_internal_CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
 #define CreateFile_utf8 flac_internal_CreateFile_utf8
+#endif
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/src/flac/decode.c b/src/flac/decode.c
index 3a6997b..a3c222c 100644
--- a/src/flac/decode.c
+++ b/src/flac/decode.c
@@ -25,10 +25,11 @@
 #include <math.h> /* for floor() */
 #include <stdio.h> /* for FILE etc. */
 #include <string.h> /* for strcmp(), strerror() */
+#define FLAC__COMPAT_USE_WINAPI /* for CreateFile_utf8 */
 #include "FLAC/all.h"
+#include "share/compat.h"
 #include "share/grabbag.h"
 #include "share/replaygain_synthesis.h"
-#include "share/compat.h"
 #include "decode.h"
 
 typedef struct {
diff --git a/src/libFLAC/windows_unicode_filenames.c b/src/libFLAC/windows_unicode_filenames.c
index ef02753..6c26420 100644
--- a/src/libFLAC/windows_unicode_filenames.c
+++ b/src/libFLAC/windows_unicode_filenames.c
@@ -34,6 +34,7 @@
 #endif
 
 #include <io.h>
+#define FLAC__COMPAT_USE_WINAPI
 #include "share/windows_unicode_filenames.h"
 
 /* convert UTF-8 back to WCHAR. Caller is responsible for freeing memory */
diff --git a/src/share/grabbag/file.c b/src/share/grabbag/file.c
index 73f7fca..fb784b9 100644
--- a/src/share/grabbag/file.c
+++ b/src/share/grabbag/file.c
@@ -46,6 +46,7 @@
 #include <windows.h>
 #include <winbase.h>
 #endif
+#define FLAC__COMPAT_USE_WINAPI /* for CreateFile_utf8 */
 #include "share/grabbag.h"
 
 
