Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Although this is an old thread, I just spent most of this morning searching for a method for identifying the Windows <em>codepage</em> given a specific <em>charset</em> ID (when the current keyboard layout/locale is NOT set to that charset). I figured that the sample code might be of use to others looking for similar information.</p> <p>In my case I wanted to map a charset value such as 161 (Greek) to equivalent Windows codepage, 1253. After a <em>lot</em> of digging I came up with the following:</p> <pre><code>/* * Convert a font charset value (e.g. 161 - Greek) into a Windows codepage (1253 for Greek) */ UINT CodepageFromCharset(UINT nCharset) { UINT nCodepage = CP_ACP; CHARSETINFO csi = {0}; // Note, the symbol charset (2, CS_SYMBOL) translates to the symbol codepage (42, CP_SYMBOL). // However, this codepage does NOT produce valid character translations so the ANSI charset // (ANSI_CHARSET) is used instead. This appears to be a known problem. // See this discussion: "More than you ever wanted to know about CP_SYMBOL" // (http://www.siao2.com/2005/11/08/490495.aspx) if (nCharset == SYMBOL_CHARSET) nCharset = 0; DWORD* lpdw = (DWORD*)nCharset; // Non-zero return value indicates success... if (TranslateCharsetInfo(lpdw, &amp;csi, TCI_SRCCHARSET) == 0) { // This should *not* happen but just in case make sure we use a valid default codepage. #ifdef _UNICODE csi.ciACP = 1200; #else csi.ciACP = CP_ACP; #endif } return csi.ciACP; } </code></pre> <p>Hope this is useful for others!</p> <p>John</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload