@@ -3,7 +3,7 @@
#include "qemu-common.h"
#define AUDIO_CAP "win-int"
-#include <windows.h>
+#include "qemu/winapi.h"
#include <mmsystem.h>
#include "audio.h"
@@ -32,7 +32,7 @@
#define AUDIO_CAP "dsound"
#include "audio_int.h"
-#include <windows.h>
+#include "qemu/winapi.h"
#include <mmsystem.h>
#include <objbase.h>
#include <dsound.h>
@@ -7,7 +7,7 @@
#define AUDIO_CAP "winwave"
#include "audio_int.h"
-#include <windows.h>
+#include "qemu/winapi.h"
#include <mmsystem.h>
#include "audio_win_int.h"
@@ -47,7 +47,7 @@
#endif
#ifdef _WIN32
-#include <windows.h>
+#include "qemu/winapi.h"
#endif
struct BdrvDirtyBitmap {
@@ -23,13 +23,13 @@
*/
#include "qemu-common.h"
#include "qemu/timer.h"
+#include "qemu/winapi.h" /* HANDLE (in raw-aio.h) */
#include "block/block_int.h"
#include "qemu/module.h"
#include "raw-aio.h"
#include "trace.h"
#include "block/thread-pool.h"
#include "qemu/iov.h"
-#include <windows.h>
#include <winioctl.h>
#define FTYPE_FILE 0
@@ -23,13 +23,13 @@
*/
#include "qemu-common.h"
#include "qemu/timer.h"
+#include "qemu/winapi.h" /* HANDLE (in raw-aio.h) */
#include "block/block_int.h"
#include "qemu/module.h"
#include "block/aio.h"
#include "raw-aio.h"
#include "qemu/event_notifier.h"
#include "qemu/iov.h"
-#include <windows.h>
#include <winioctl.h>
#define FTYPE_FILE 0
@@ -670,7 +670,7 @@ fi
if test "$mingw32" = "yes" ; then
EXESUF=".exe"
DSOSUF=".dll"
- QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
+ QEMU_CFLAGS="-DWINVER=_WIN32_WINNT_WINXP $QEMU_CFLAGS"
# enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS"
@@ -16,7 +16,7 @@
#include "qemu-common.h"
#ifdef _WIN32
-#include <windows.h>
+#include "qemu/winapi.h"
#endif
struct EventNotifier {
@@ -3,7 +3,7 @@
#define QEMU_SOCKET_H
#ifdef _WIN32
-#include <windows.h>
+#include "qemu/winapi.h"
#include <winsock2.h>
#include <ws2tcpip.h>
@@ -1,6 +1,6 @@
#ifndef __QEMU_THREAD_WIN32_H
#define __QEMU_THREAD_WIN32_H 1
-#include "windows.h"
+#include "qemu/winapi.h"
struct QemuMutex {
CRITICAL_SECTION lock;
new file mode 100644
@@ -0,0 +1,22 @@
+/*
+ * QEMU interface to the Windows API
+ *
+ * Copyright (c) 2014 Stefan Weil
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2
+ * or later. See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_WINAPI_H
+#define QEMU_WINAPI_H
+
+/* Don't include some less frequently used APIs. */
+#define WIN32_LEAN_AND_MEAN
+
+#if !defined(WINVER)
+# error Add -DWINVER=_WIN32_WINNT_WINXP to compiler options
+#endif
+
+#include <windows.h>
+
+#endif /* QEMU_WINAPI_H */
@@ -26,7 +26,7 @@
#ifndef QEMU_OS_WIN32_H
#define QEMU_OS_WIN32_H
-#include <windows.h>
+#include "qemu/winapi.h"
#include <winsock2.h>
/* Workaround for older versions of MinGW. */
@@ -35,7 +35,7 @@
#include "sysemu/sysemu.h"
#include "qemu/error-report.h"
#include <stdio.h>
-#include <windows.h>
+#include "qemu/winapi.h"
#include <winioctl.h>
//=============
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include <windows.h>
+#include "qemu/winapi.h"
#include <mmsystem.h>
#include <unistd.h>
#include <fcntl.h>
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <glib.h>
-#include <windows.h>
+#include "qemu/winapi.h"
#include <errno.h>
#include <io.h>
#include "qga/guest-agent-core.h"
@@ -11,8 +11,8 @@
* See the COPYING file in the top-level directory.
*/
+#include "qemu/winapi.h" /* OpenProcessToken, ... */
#include <glib.h>
-#include <wtypes.h>
#include <powrprof.h>
#include "qga/guest-agent-core.h"
#include "qga/vss-win32.h"
@@ -13,7 +13,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
-#include <windows.h>
+#include "qemu/winapi.h"
#include "qga/service-win32.h"
static int printf_win_error(const char *text)
@@ -13,7 +13,7 @@
#ifndef QGA_SERVICE_H
#define QGA_SERVICE_H
-#include <windows.h>
+#include "qemu/winapi.h"
#define QGA_SERVICE_DISPLAY_NAME "QEMU Guest Agent"
#define QGA_SERVICE_NAME "qemu-ga"
@@ -11,7 +11,7 @@
*/
#include <stdio.h>
-#include <windows.h>
+#include "qemu/winapi.h"
#include "qga/guest-agent-core.h"
#include "qga/vss-win32.h"
#include "qga/vss-win32/requester.h"
@@ -15,7 +15,7 @@
#define __MIDL_user_allocate_free_DEFINED__
#include "config-host.h"
-#include <windows.h>
+#include "qemu/winapi.h"
#include <shlwapi.h>
/* Reduce warnings to include vss.h */
@@ -9,7 +9,7 @@
typedef char *caddr_t;
-# include <windows.h>
+# include "qemu/winapi.h"
# include <winsock2.h>
# include <ws2tcpip.h>
# include <sys/timeb.h>
@@ -17,7 +17,7 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _WIN32
-#include <windows.h>
+#include "qemu/winapi.h"
#else
#include <sys/types.h>
#include <sys/mman.h>
@@ -22,9 +22,6 @@
* THE SOFTWARE.
*/
-/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
-#undef WIN32_LEAN_AND_MEAN
-
#include <SDL.h>
#if SDL_MAJOR_VERSION == 1
@@ -25,7 +25,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include <windows.h>
+#include "qemu/winapi.h"
#include <glib.h>
#include <stdlib.h>
#include "config-host.h"
Including windows.h from the new file include/qemu/winapi.h allows better tracking of the files which depend on the Windows API. 1864 *.o files depend on windows.h in a typical build, only 88 *.o files don't. The windows.h specific macro WIN32_LEAN_AND_MEAN is now defined in the new file and no longer part of the QEMU_CFLAGS. A hack in ui/sdl.c can be removed after this change. WINVER is still needed for all compilations with MinGW, so it cannot be defined in the new file. Replace its numeric value by a symbolic value to show which API is requested. Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Jan Kiszka <jan.kiszka@siemens.com> Cc: Anthony Liguori <aliguori@amazon.com> Cc: Kevin Wolf <kwolf@redhat.com> Cc: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de> --- audio/audio_win_int.c | 2 +- audio/dsoundaudio.c | 2 +- audio/winwaveaudio.c | 2 +- block.c | 2 +- block/raw-win32.c | 2 +- block/win32-aio.c | 2 +- configure | 2 +- include/qemu/event_notifier.h | 2 +- include/qemu/sockets.h | 2 +- include/qemu/thread-win32.h | 2 +- include/qemu/winapi.h | 22 ++++++++++++++++++++++ include/sysemu/os-win32.h | 2 +- net/tap-win32.c | 2 +- os-win32.c | 2 +- qga/channel-win32.c | 2 +- qga/commands-win32.c | 2 +- qga/service-win32.c | 2 +- qga/service-win32.h | 2 +- qga/vss-win32.c | 2 +- qga/vss-win32/vss-common.h | 2 +- slirp/slirp.h | 2 +- translate-all.c | 2 +- ui/sdl.c | 3 --- util/oslib-win32.c | 2 +- 24 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 include/qemu/winapi.h