Sunday, April 26, 2020

Consuming Unicode filenames from the C/C++ command line


#define _UNICODE
#include <windows.h>
#include <cwchar>
#include <cstdio>

using namespace std;

int main() {

    int argc;
    wchar_t** argv = CommandLineToArgvW( GetCommandLineW(), &argc); //consumer Unicode

    if (argc != 3) {
        wprintf(L"usage: this [file] [text]\n");
        return 1;
    }

    FILE* out = _wfopen( argv[1], L"wb");

    if (!out) {
        return 1;
    }

    fwprintf(out, L"%c", 0xFEFF);
    fwprintf(out, L"%s", argv[2]);
    fclose(out);

}

No comments:

Post a Comment