diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 163856d..ff7de38 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -962,8 +962,12 @@ pg_newlocale_from_collation(Oid collid)
 		if (strcmp(collcollate, collctype) == 0)
 		{
 			/* Normal case where they're the same */
+#ifndef WIN32
 			result = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collcollate,
 							   NULL);
+#else
+			result = _create_locale(LC_ALL, collcollate);
+#endif
 			if (!result)
 				ereport(ERROR,
 						(errcode_for_file_access(),
@@ -972,6 +976,7 @@ pg_newlocale_from_collation(Oid collid)
 		}
 		else
 		{
+#ifndef WIN32
 			/* We need two newlocale() steps */
 			locale_t loc1;
 
@@ -987,6 +992,9 @@ pg_newlocale_from_collation(Oid collid)
 						(errcode_for_file_access(),
 						 errmsg("could not create locale \"%s\": %m",
 								collctype)));
+#else
+			elog(ERROR, "not supported");
+#endif
 		}
 
 		cache_entry->locale = result;
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 3587fe4..04b0326 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -1374,7 +1374,10 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
 			((LPWSTR) a2p)[r] = 0;
 
 			errno = 0;
-			result = wcscoll((LPWSTR) a1p, (LPWSTR) a2p);
+			if (mylocale)
+				result = _wcscoll_l((LPWSTR) a1p, (LPWSTR) a2p, mylocale);
+			else
+				result = wcscoll((LPWSTR) a1p, (LPWSTR) a2p);
 			if (result == 2147483647)	/* _NLSCMPERROR; missing from mingw
 										 * headers */
 				ereport(ERROR,
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 79b8036..8eae0b4 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -683,3 +683,5 @@
 /* Define to empty if the keyword `volatile' does not work. Warning: valid
    code using `volatile' can become incorrect without. Disable with care. */
 /* #undef volatile */
+
+#define HAVE_LOCALE_T 1
diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h
index 4c72fd0..370d691 100644
--- a/src/include/utils/pg_locale.h
+++ b/src/include/utils/pg_locale.h
@@ -17,6 +17,17 @@
 #include <xlocale.h>
 #endif
 
+#ifdef WIN32
+#define locale_t _locale_t
+#define towlower_l _towlower_l
+#define towupper_l _towupper_l
+#define toupper_l _toupper_l
+#define tolower_l _tolower_l
+#define iswalnum_l _iswalnum_l
+#define isalnum_l _isalnum_l
+#define strcoll_l _strcoll_l
+#endif
+
 #include "utils/guc.h"
 
 
