I am writing a library for the printer. The input is text in UTF-8 format. The printer prints Cyrillic in CP866 (Cyrillic) format. How to convert UTF-8 to CP866? Perhaps there are special features?
1 answer
ifstream file("text.txt"); char pszCode[30]; file.getline(pszCode, 30); BSTR bstrWide; char pszAnsi[50]; int nLength; char* text = ""; nLength = MultiByteToWideChar(CP_UTF8, 0, pszCode, strlen(pszCode) + 1, NULL, NULL); bstrWide = SysAllocStringLen(NULL, nLength); MultiByteToWideChar(CP_UTF8, 0, pszCode, strlen(pszCode) + 1, bstrWide, nLength); nLength = WideCharToMultiByte(CP_OEMCP, 0, bstrWide, -1, NULL, 0, NULL, NULL); WideCharToMultiByte(CP_OEMCP, 0, bstrWide, -1, pszAnsi, nLength, NULL, NULL); SysFreeString(bstrWide); cout << pszAnsi << endl; In general, I used this method, as VladD advised, in principle everything works, although of course I did not understand how these two functions work to the end. But thanks anyway!
|
dwFlagsinMultiByteToWideCharspecified (if yes, then the function will not work for UTF-8)? 3.WC_ERR_INVALID_CHARSnot found anywhere? - ߊߚߤߘ