diff --git a/src/file_win.cpp b/src/file_win.cpp index 348e50f8d..5fc647439 100644 --- a/src/file_win.cpp +++ b/src/file_win.cpp @@ -60,7 +60,12 @@ namespace { char *buffer=0; int err = GetLastError(); - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, err, 0, (LPWSTR)(LPCSTR)&buffer, 0, 0); + + #ifdef _UNICODE + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, err, 0, (LPWSTR)(LPCSTR)&buffer, 0, 0); + #else + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, err, 0, (LPSTR)&buffer, 0, 0); + #endif auto_LocalFree auto_free(buffer); // needed for exception safety std::stringstream s; @@ -106,6 +111,7 @@ namespace libtorrent assert(access_mask & (GENERIC_READ | GENERIC_WRITE)); + #ifdef _UNICODE HANDLE new_handle = CreateFile( (LPCWSTR)file_name , access_mask @@ -114,6 +120,16 @@ namespace libtorrent , (flags & read_flag)?OPEN_EXISTING:OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , 0); + #else + HANDLE new_handle = CreateFile( + file_name + , access_mask + , FILE_SHARE_READ + , 0 + , (flags & read_flag)?OPEN_EXISTING:OPEN_ALWAYS + , FILE_ATTRIBUTE_NORMAL + , 0); + #endif if (new_handle == INVALID_HANDLE_VALUE) {