mojoshader_preprocessor.c
changeset 861 760e1457ffc6
parent 858 d51537335896
child 864 aa3bec973a21
--- a/mojoshader_preprocessor.c	Wed Feb 24 11:42:16 2010 -0500
+++ b/mojoshader_preprocessor.c	Wed Feb 24 18:40:48 2010 +0200
@@ -203,7 +203,41 @@
                                      void *d)
 {
 #ifdef _MSC_VER
-#error Write me.
+	WCHAR widePath[MAX_PATH];
+	if (!MultiByteToWideChar( CP_UTF8, 0, fname, -1, widePath, MAX_PATH ))
+		return 0;
+	HANDLE fileHandle = CreateFileW (widePath, FILE_GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, NULL, NULL );
+	if (fileHandle == INVALID_HANDLE_VALUE)
+		return 0;
+	DWORD fileSize = GetFileSize (fileHandle, NULL);
+	if (fileSize == INVALID_FILE_SIZE)
+	{
+		CloseHandle (fileHandle);
+		return 0;
+	}
+	char *data = (char *) m(fileSize, d);
+	if (data == NULL)
+	{
+		CloseHandle (fileHandle);
+		return 0;
+	}
+	DWORD readLength = 0;
+	if (!ReadFile( fileHandle, data, fileSize, &readLength, NULL))
+	{
+		CloseHandle (fileHandle);
+		f(data, d);
+		return 0;
+	}
+	CloseHandle (fileHandle);
+	if (readLength != fileSize)
+	{
+		f(data, d);
+		return 0;
+	}
+	*outdata = data;
+	*outbytes = fileSize;
+	return 1;
+	
 #else
     struct stat statbuf;
     if (stat(fname, &statbuf) == -1)