Created
September 7, 2016 22:31
-
-
Save wareya/b56173daad2eab12dc997cf668c69f0c to your computer and use it in GitHub Desktop.
_wfopen wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if _WIN32 | |
#define WIN32_LEAN_AND_MEAN | |
#include <windows.h> | |
static inline FILE* wrap_fopen(const char* X, const char* Y) | |
{ | |
size_t X_S = MultiByteToWideChar(CP_UTF8, 0, X, -1, NULL, 0)*sizeof(wchar_t); | |
size_t Y_S = MultiByteToWideChar(CP_UTF8, 0, Y, -1, NULL, 0)*sizeof(wchar_t); | |
std::wstring W_X(X_S, L'#'); | |
std::wstring W_Y(Y_S, L'#'); | |
MultiByteToWideChar(CP_UTF8, 0, X, -1, &W_X[0], X_S); | |
MultiByteToWideChar(CP_UTF8, 0, Y, -1, &W_Y[0], Y_S); | |
printf("Going to open %s (%ls)\n", X, W_X.data()); | |
return _wfopen(W_X.data(),W_Y.data()); | |
} | |
#define fopen wrap_fopen | |
#endif | |
#include <stb_image.h> | |
#if _WIN32 | |
#undef fopen | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment