diff --git a/glib/gdir.c b/glib/gdir.c
index 9919bbb..b6e71c0 100644
--- a/glib/gdir.c
+++ b/glib/gdir.c
@@ -50,7 +50,7 @@
 
 struct _GDir
 {
-#ifdef G_OS_WIN32
+#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
   _WDIR *wdirp;
 #else
   DIR *dirp;
@@ -84,7 +84,7 @@ g_dir_open (const gchar  *path,
 {
   GDir *dir;
   int errsv;
-#ifdef G_OS_WIN32
+#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
   wchar_t *wpath;
 #else
   gchar *utf8_path;
@@ -92,7 +92,7 @@ g_dir_open (const gchar  *path,
 
   g_return_val_if_fail (path != NULL, NULL);
 
-#ifdef G_OS_WIN32
+#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
   wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, error);
 
   if (wpath == NULL)
@@ -197,7 +197,7 @@ g_dir_open (const gchar  *path,
 const gchar *
 g_dir_read_name (GDir *dir)
 {
-#ifdef G_OS_WIN32
+#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
   gchar *utf8_name;
   struct _wdirent *wentry;
 #else
@@ -206,7 +206,7 @@ g_dir_read_name (GDir *dir)
 
   g_return_val_if_fail (dir != NULL, NULL);
 
-#ifdef G_OS_WIN32
+#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
   while (1)
     {
       wentry = _wreaddir (dir->wdirp);
@@ -287,7 +287,7 @@ g_dir_rewind (GDir *dir)
 {
   g_return_if_fail (dir != NULL);
   
-#ifdef G_OS_WIN32
+#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
   _wrewinddir (dir->wdirp);
 #else
   rewinddir (dir->dirp);
@@ -305,7 +305,7 @@ g_dir_close (GDir *dir)
 {
   g_return_if_fail (dir != NULL);
 
-#ifdef G_OS_WIN32
+#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
   _wclosedir (dir->wdirp);
 #else
   closedir (dir->dirp);
