7

Is there any wrapper library out there that mimics the Windows "ANSI" function names (e.g. CreateFileA), assumes the inputs are in UTF-8, converts them to UTF-16, calls the UTF-16 version of the function (e.g. CreateFileW), and converts the outputs back to UTF-8 for the program?

It would allow ASCII programs to use UTF-8 almost seamlessly.

6
  • 4
    AFAIK - no, there're too many Windows API functions. Commented May 1, 2012 at 4:11
  • You can convert an ASCII string into UTF-16 trivially. Commented May 1, 2012 at 9:46
  • It's probably simplest to bite the bullet and use the UTF-16 versions of the Windows API functions everywhere. If you the strings are coming from UTF-8 sources, it's probably easier to wrap those. Commented May 1, 2012 at 10:43
  • @valdo: Yeah I was thinking the same thing, but just wanted to ask in case there was one I didn't know about. Commented May 1, 2012 at 20:07
  • 1
    File a bug with Microsoft that CP_ACP can't be set CP_UTF8. If it could then the A functions would work fine and you wouldn't need a wrapper library. Commented May 3, 2012 at 16:30

3 Answers 3

2

Rather than wrapping the API functions, it's easier to wrap the strings in a conversion function. Then you'll be future-proof when the next version of Windows adds more API functions.

Sign up to request clarification or add additional context in comments.

3 Comments

I'd hate to -1, but this is really not answering the question. :\
@Mehrdad, that's your right. While it might not be the answer to the question as asked, it is the answer to the problem behind the question.
That's assuming you have access to the source code. But if you had a library like this, you wouldn't need the source code -- you could just compile the library as a DLL and redirect the functions at runtime.
1

As others said, there are too many WinAPI functions to make such a library feasible. However one can hack it on the tool-chain level or using something like http://research.microsoft.com/en-us/projects/detours/.

EDIT: Windows 10 added support for UTF-8 codepage in ANSI API.

Comments

0

There is this thing called WDL, it has some UTF-8 wrappers (win32_utf8). I have never tried it so I don't know how complete the support is.

1 Comment

It only seems to have wrappers for a handful of functions (about ~30).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.