Skip to content

Instantly share code, notes, and snippets.

@tonycoz
Created March 10, 2025 03:15
Show Gist options
  • Save tonycoz/aa6ba4155a3e4a9f70dc50a05b347a3e to your computer and use it in GitHub Desktop.
Save tonycoz/aa6ba4155a3e4a9f70dc50a05b347a3e to your computer and use it in GitHub Desktop.
C:\Users\Tony\dev\perl\git>type mbsurr.c
#include <windows.h>
#include <stdio.h>
char mbcs[] = "\xED\xA0\x81"; // D801
int main() {
wchar_t out[20];
int len = MultiByteToWideChar(CP_UTF8, 0, mbcs, -1, out, 20);
printf("len %d error %lu\n", len, (unsigned long)GetLastError());
for (int i = 0; i < len; ++i) {
printf("%04x\n", out[i]);
}
}
C:\Users\Tony\dev\perl\git>cl mbsurr.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.43.34808 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
mbsurr.c
Microsoft (R) Incremental Linker Version 14.43.34808.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:mbsurr.exe
mbsurr.obj
C:\Users\Tony\dev\perl\git>mbsurr
len 3 error 0
fffd
fffd
0000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment