This is another way to do this. This is not so straightforward, but when you do not want to type 6 arguments in a very specific order and remember the code numbers / macros of MultiByteToWideChar , it does the job. It takes 16 microseconds on this laptop, most of which (9 microseconds) were spent on AddAtomW .
For reference, MultiByteToWideChar takes from 0 to 1 microseconds.
#include <Windows.h> const wchar_t msg[] = L"We did it!"; int main(int argc, char **argv) { char result[(sizeof(msg) / 2) + 1]; ATOM tmp; tmp = AddAtomW(msg); GetAtomNameA(tmp, result, sizeof(result)); MessageBoxA(NULL ,result,"it says", MB_OK | MB_ICONINFORMATION); DeleteAtom(tmp); return 0; }
source share