test: chartran.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# chartran.c

Go to the documentation of this file.

    00001 /****************************** Module Header ******************************\
    00002 * Module Name: chartran.c
    00003 *
    00004 * Copyright (c) 1985 - 1999, Microsoft Corporation
    00005 *
    00006 * This module contains the routines for translating ACP characters
    00007 * to Unicode and translating Unicode characters to ACP characters.
    00008 * NOTE: The ACP is the currently installed 8-bit code page.
    00009 *
    00010 *
    00011 * History:
    00012 * 08-01-91 GregoryW      Created.
    00013 * 05-14-92 GregoryW      Modified to use the Rtl translation routines.
    00014 \***************************************************************************/
    00015
    00016 extern __declspec(dllimport) USHORT NlsAnsiCodePage;
    00017
    00018 #ifndef THREAD_CODEPAGE
    00019 #ifdef _USERK_
    00020 #define THREAD_CODEPAGE() (PtiCurrent()->pClientInfo->CodePage)
    00021 #else
    00022 #define THREAD_CODEPAGE() (GetClientInfo()->CodePage)
    00023 #endif // _USERK_
    00024 #endif
    00025
    00026
    00027 #define IS_ACP(cp) (((cp) == NlsAnsiCodePage) || ((cp) == CP_ACP))
    00028
    00029 /***************************************************************************\
    00030 * WCSToMBEx (API)
    00031 *
    00032 * Convert a wide-character (Unicode) string to MBCS (ANSI) string.
    00033 *
    00034 * nAnsiChar > 0 indicates the number of bytes to allocate to store the
    00035 *    ANSI string (if bAllocateMem == TRUE) or the size of the buffer
    00036 *    pointed to by *pAnsiString (bAllocateMem == FALSE).
    00037 *
    00038 * nAnsiChar == -1 indicates that the necessary number of bytes be allocated
    00039 *    to hold the translated string.  bAllocateMem must be set to TRUE in
    00040 *    this case.
    00041 *
    00042 * Return value
    00043 *   Success: number of characters in the output string
    00044 *        If bAllocateMem was TRUE, then FreeAnsiString() may be
    00045 *        used to free the allocated memory at *ppAnsiString.
    00046 *   Failure: 0 means failure
    00047 *        (Any buffers allocated by this routine are freed)
    00048 *
    00049 * History:
    00050 *  1992-??-?? GregoryW   Created
    00051 *  1993-01-07 IanJa      fix memory leak on error case.
    00052 \***************************************************************************/
    00053
    00054 int
    00055 WCSToMBEx(
    00056     WORD wCodePage,
    00057     LPCWSTR pUnicodeString,
    00058     int cchUnicodeString,
    00059     LPSTR *ppAnsiString,
    00060     int nAnsiChar,
    00061     BOOL bAllocateMem)
    00062 {
    00063     ULONG nCharsInAnsiString;
    00064 #ifdef _USERK_
    00065     INT iCharsInAnsiString;
    00066 #endif // _USERK_
    00067
    00068     if (nAnsiChar == 0 || cchUnicodeString == 0 || pUnicodeString == NULL) {
    00069         return 0;      // nothing to translate or nowhere to put it
    00070     }
    00071
    00072     /*
    00073      * Adjust the cchUnicodeString value.  If cchUnicodeString == -1 then the
    00074      * string pointed to by pUnicodeString is NUL terminated so we
    00075      * count the number of bytes.  If cchUnicodeString < -1 this is an
    00076      * illegal value so we return FALSE.  Otherwise, cchUnicodeString is
    00077      * set and requires no adjustment.
    00078      */
    00079     if (cchUnicodeString == -1) {
    00080         cchUnicodeString = (wcslen(pUnicodeString) + 1);
    00081     } else if (cchUnicodeString < -1) {
    00082         return 0;     // illegal value
    00083     }
    00084
    00085     /*
    00086      * Adjust the nAnsiChar value.  If nAnsiChar == -1 then we pick a
    00087      * value based on cchUnicodeString to hold the converted string.  If
    00088      * nAnsiChar < -1 this is an illegal value so we return FALSE.
    00089      * Otherwise, nAnsiChar is set and requires no adjustment.
    00090      */
    00091     if (nAnsiChar == -1) {
    00092         if (bAllocateMem == FALSE) {
    00093             return 0;  // no destination
    00094         }
    00095         nAnsiChar = cchUnicodeString * DBCS_CHARSIZE;
    00096     } else if (nAnsiChar < -1) {
    00097         return 0;     // illegal value
    00098     }
    00099
    00100     if (bAllocateMem) {
    00101         /*
    00102          * We need to allocate memory to hold the translated string.
    00103          */
    00104         *ppAnsiString = (LPSTR)UserRtlAllocMem(nAnsiChar);
    00105         if (*ppAnsiString == NULL) {
    00106             return 0;
    00107         }
    00108     }
    00109
    00110     /*
    00111      * translate Unicode string pointed to by pUnicodeString into
    00112      * ANSI and store in location pointed to by pAnsiString.  We
    00113      * stop translating when we fill up the ANSI buffer or reach
    00114      * the end of the Unicode string.
    00115      */
    00116
    00117     /*
    00118      * if the target multibyte codepage is eqaul to ACP, Call faster Rtl function.
    00119      */
    00120     if (IS_ACP(wCodePage)) {
    00121
    00122         NTSTATUS Status;
    00123
    00124         Status = RtlUnicodeToMultiByteN(
    00125                         (PCH)*ppAnsiString,
    00126                         nAnsiChar,
    00127                         &nCharsInAnsiString,
    00128                         (PWCH)pUnicodeString,
    00129                         cchUnicodeString * sizeof(WCHAR));
    00130         /*
    00131          * If the ansi buffer is too small, RtlUnicodeToMultiByteN()
    00132          * returns STATUS_BUFFER_OVERFLOW. In this case, the function
    00133          * put as many ansi characters as specified in the buffer and
    00134          *  returns the number by chacacters(in bytes) written. We would
    00135          * like to return the actual byte  count written in the ansi
    00136          * buffer rather than returnning 0 since callers of this function
    00137          * don't expect to be returned 0 in most case.
    00138          */
    00139
    00140         if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW) {
    00141             if (bAllocateMem) {
    00142                 UserRtlFreeMem(*ppAnsiString);
    00143             }
    00144             return 0;   // translation failed
    00145         }
    00146
    00147         return (int)nCharsInAnsiString;
    00148
    00149     } else {
    00150
    00151 #ifdef _USERK_
    00152         /*
    00153          * Call GRE to convert string to Unicode. (Kernel mode)
    00154          */
    00155
    00156         iCharsInAnsiString = EngWideCharToMultiByte(
    00157                                  (UINT)wCodePage,
    00158                                  (LPWSTR)pUnicodeString,
    00159                                  cchUnicodeString * sizeof(WCHAR),
    00160                                  (LPSTR)*ppAnsiString,
    00161                                  nAnsiChar);
    00162
    00163         nCharsInAnsiString = (iCharsInAnsiString == -1) ? 0 :
    00164                                                           (ULONG) iCharsInAnsiString;
    00165
    00166 #else
    00167         /*
    00168          * Call NLS API (Kernel32) to convert string to Unicode. (User mode)
    00169          */
    00170         nCharsInAnsiString = WideCharToMultiByte(
    00171                                  (UINT)wCodePage, 0,
    00172                                  (LPCWSTR)pUnicodeString,
    00173                                  cchUnicodeString,
    00174                                  (LPSTR)*ppAnsiString,
    00175                                  nAnsiChar,
    00176                                  NULL, NULL);
    00177 #endif // _USERK_
    00178
    00179         if (nCharsInAnsiString == 0) {
    00180             if (bAllocateMem) {
    00181                 UserRtlFreeMem(*ppAnsiString);
    00182             }
    00183         }
    00184
    00185         return (int)nCharsInAnsiString;
    00186     }
    00187 }
    00188
    00189 // Returns number of character converted
    00190
    00191 int MBToWCSEx(
    00192     WORD wCodePage,
    00193     LPCSTR pAnsiString,
    00194     int nAnsiChar,
    00195     LPWSTR *ppUnicodeString,
    00196     int cchUnicodeString,
    00197     BOOL bAllocateMem)
    00198 {
    00199     ULONG nBytesInUnicodeString;
    00200
    00201     if (nAnsiChar == 0 || cchUnicodeString == 0 || pAnsiString == NULL) {
    00202         return 0;      // nothing to translate or nowhere to put it
    00203     }
    00204
    00205     /*
    00206      * Adjust the nAnsiChar value.  If nAnsiChar == -1 then the
    00207      * string pointed to by pAnsiString is NUL terminated so we
    00208      * count the number of bytes.  If nAnsiChar < -1 this is an
    00209      * illegal value so we return FALSE.  Otherwise, nAnsiChar is
    00210      * set and requires no adjustment.
    00211      */
    00212
    00213 #ifdef _USERK_
    00214     UserAssert(nAnsiChar >= USER_AWCONV_COUNTSTRINGSZ);
    00215 #endif
    00216     if (nAnsiChar < 0) {
    00217
    00218         /*
    00219          *  Bug 268035 - joejo
    00220          *  Need to fail if the count is a negative number less than -2!
    00221          */
    00222         if (nAnsiChar < USER_AWCONV_COUNTSTRINGSZ) {
    00223             return 0;
    00224         }
    00225
    00226 #if (USER_AWCONV_COUNTSTRING != -1 || USER_AWCONV_COUNTSTRINGSZ != -2)
    00227 #error USER_AWCONV_COUNTSTRING or USER_AWCONV_COUNTSTRINGSZ has unexpected value.
    00228 #endif
    00229         /* HACK HACK HACK
    00230          * If nAnsiChar is -1 (USER_AWCONV_COUNTSTRING), nAnsiChar length will be strlen() + 1,
    00231          * to allocate the memory including trailing \0: this is compatible to the original code.
    00232          * If nAnsiCahr is -2 (USER_AWCONV_COUNTSTRINGSZ), memory for trailing \0 will not be needed,
    00233          * so memory allocation is optimized and the return value would be same as strlen().
    00234          */
    00235         nAnsiChar = strlen(pAnsiString) + 2 + nAnsiChar;   // don't forget the NUL if nAnsiChar == -1
    00236
    00237         if (nAnsiChar == 0) {
    00238             return 0;
    00239         }
    00240     }
    00241
    00242     /*
    00243      * Adjust the cchUnicodeString value.  If cchUnicodeString == -1 then we
    00244      * pick a value based on nAnsiChar to hold the converted string.  If
    00245      * cchUnicodeString < -1 this is an illegal value so we return FALSE.
    00246      * Otherwise, cchUnicodeString is set and requires no adjustment.
    00247      */
    00248     if (cchUnicodeString == -1) {
    00249         if (bAllocateMem == FALSE) {
    00250             return 0;    // no destination
    00251         }
    00252         cchUnicodeString = nAnsiChar;
    00253     } else if (cchUnicodeString < -1) {
    00254         return 0;     // illegal value
    00255     }
    00256
    00257     if (bAllocateMem) {
    00258         *ppUnicodeString = (LPWSTR)UserRtlAllocMem(cchUnicodeString*sizeof(WCHAR));
    00259         if (*ppUnicodeString == NULL) {
    00260             return 0;    // allocation failed
    00261         }
    00262     }
    00263
    00264     /*
    00265      * if codepage is CP_ACP, We will call faster RtlXXX function.
    00266      */
    00267     if (IS_ACP(wCodePage)) {
    00268         /*
    00269          * translate ANSI string pointed to by pAnsiString into Unicode
    00270          * and store in location pointed to by pUnicodeString.  We
    00271          * stop translating when we fill up the Unicode buffer or reach
    00272          * the end of the ANSI string.
    00273          */
    00274         if (!NT_SUCCESS(RtlMultiByteToUnicodeN(
    00275                             (PWCH)*ppUnicodeString,
    00276                             cchUnicodeString * sizeof(WCHAR),
    00277                             &nBytesInUnicodeString,
    00278                             (PCH)pAnsiString,
    00279                             nAnsiChar
    00280                             ))) {
    00281             if (bAllocateMem) {
    00282                 UserRtlFreeMem(*ppUnicodeString);
    00283             }
    00284             return 0;   // translation failed
    00285         }
    00286
    00287         return (int)(nBytesInUnicodeString / sizeof(WCHAR));
    00288
    00289     } else {
    00290         /*
    00291          * if wCodePage is not ACP, Call NLS API.
    00292          */
    00293         ULONG nCharsInUnicodeString;
    00294
    00295 #ifdef _USERK_
    00296
    00297         /*
    00298          * I believe we will never hit this code which is why I am
    00299          * adding this assert.  [gerritv] 5-21-96
    00300          */
    00301 #define SHOULD_NOT_REACH_HERE   0
    00302         UserAssert(SHOULD_NOT_REACH_HERE);
    00303 #undef  SHOULD_NOT_REACH_HERE
    00304         return 0;
    00305
    00306 #if 0   // FYI: old code
    00307         INT   iCharsInUnicodeString;
    00308
    00309         /*
    00310          * Call GRE to convert string to Unicode. (Kernel mode)
    00311          * I believe we will never hit this code which is why I am
    00312          * adding this assert.  [gerritv] 5-21-96
    00313          */
    00314
    00315         UserAssert(0);
    00316
    00317         iCharsInUnicodeString = EngMultiByteToWideChar(
    00318                                     (UINT)wCodePage,
    00319                                     (LPWSTR)*ppUnicodeString,
    00320                                     (int)cchUnicodeString * sizeof(WCHAR),
    00321                                     (LPSTR)pAnsiString,
    00322                                     (int)nAnsiChar);
    00323
    00324         nCharsInUnicodeString = (iCharsInUnicodeString == -1) ? 0 :
    00325                                                           (ULONG) iCharsInUnicodeString;
    00326 #endif
    00327
    00328 #else
    00329         /*
    00330          * Call NLS API (Kernel32) to convert string to Unicode. (User mode)
    00331          */
    00332         nCharsInUnicodeString = MultiByteToWideChar(
    00333                                     (UINT)wCodePage, 0,
    00334                                     (LPCSTR)pAnsiString,
    00335                                     (int)nAnsiChar,
    00336                                     (LPWSTR)*ppUnicodeString,
    00337                                     (int)cchUnicodeString);
    00338 #endif // _USERK_
    00339
    00340         if (nCharsInUnicodeString == 0) {
    00341             if (bAllocateMem) {
    00342                 UserRtlFreeMem(*ppUnicodeString);
    00343             }
    00344         }
    00345
    00346         return (int)nCharsInUnicodeString;
    00347     }
    00348
    00349 }
    00350
    00351
    00352 /**************************************************************************\
    00353 * RtlWCSMessageWParmCharToMB
    00354 *
    00355 * Converts a Wide Character to a Multibyte character; in place
    00356 * Returns the number of characters converted or zero if failure
    00357 *
    00358 * 11-Feb-1992  JohnC    Created
    00359 \**************************************************************************/
    00360
    00361 BOOL RtlWCSMessageWParamCharToMB(DWORD msg, WPARAM *pWParam)
    00362 {
    00363     DWORD dwAnsi;
    00364     NTSTATUS Status;
    00365     WORD CodePage;
    00366     int nbWch;
    00367
    00368 #ifdef FE_SB // RtlWCSMessageWParamCharToMB()
    00369     //
    00370     // Format of *pWParam here...
    00371     //
    00372     // LOWORD(*pWParam) = Unicode CodePoint...
    00373     // HIWORD(*pWParam) = Has some information for DBCS messaging
    00374     //                    (ex. WPARAM_IR_DBCSCHAR)
    00375     //
    00376     // Then we need to convert ONLY loword of wParam to Unicode...
    00377     //
    00378 #endif // FE_SB
    00379 #ifndef FE_SB
    00380     // NtBug #3135 (Closed 02/04/93)
    00381     // Publisher Posts WM_CHAR messages with wParam > 0xFF (not a valid ANSI char)!
    00382     //
    00383     // It does this to disable TranslateAccelerator for that char.
    00384     // MSPub's winproc must get the non-ANSI 'character' value, so PostMessage must
    00385     // translate *two* characters of wParam for character messages, and PeekMessage
    00386     // must translate *two* Unicode chars of wParam for ANSI app.
    00387 #endif
    00388
    00389     /*
    00390      * Only these messages have CHARs: others are passed through
    00391      */
    00392
    00393     switch(msg) {
    00394 #ifdef FE_IME // RtlWCSMessageWParamCharToMB()
    00395     case WM_IME_CHAR:
    00396     case WM_IME_COMPOSITION:
    00397 #endif // FE_IME
    00398     case WM_CHAR:
    00399     case WM_CHARTOITEM:
    00400     case EM_SETPASSWORDCHAR:
    00401     case WM_DEADCHAR:
    00402     case WM_SYSCHAR:
    00403     case WM_SYSDEADCHAR:
    00404     case WM_MENUCHAR:
    00405
    00406         CodePage = THREAD_CODEPAGE();
    00407         dwAnsi = 0;
    00408
    00409         nbWch = IS_DBCS_ENABLED() ? 1 * sizeof(WCHAR) : 2 * sizeof(WCHAR);
    00410
    00411         if (IS_ACP(CodePage)) {
    00412             // HACK HACK HACK HACK (for NtBug #3135)
    00413             // to allow applications that store data in high word of wParam
    00414             // Jan/06/96 hiroyama
    00415             Status = RtlUnicodeToMultiByteN((LPSTR)&dwAnsi, sizeof(dwAnsi),
    00416                     NULL, (LPWSTR)pWParam, nbWch);
    00417             if (!NT_SUCCESS(Status)) {
    00418                 // LATER IanJa: returning FALSE makes GetMessage fail, which
    00419                 // terminates the app.  We should use some default 'bad character'
    00420                 // I use 0x00 for now.
    00421                 *pWParam = 0x00;
    00422                 return TRUE;
    00423             }
    00424         } else {
    00425             int cwch;
    00426             // assuming little endian
    00427 #ifdef _USERK_
    00428             cwch = EngWideCharToMultiByte(CodePage,
    00429                     (LPWSTR)pWParam, nbWch,
    00430                     (LPSTR)&dwAnsi, sizeof(dwAnsi));
    00431 #else
    00432             cwch = WideCharToMultiByte(CodePage, 0,
    00433                     (LPCWSTR)pWParam, nbWch / sizeof(WCHAR),
    00434                     (LPSTR)&dwAnsi, sizeof(dwAnsi), NULL, NULL);
    00435 #endif // _USERK_
    00436             // KdPrint(("0x%04x -> 0x%02x (%d)\n", *pWParam, dwAnsi, CodePage));
    00437             if (cwch == 0) {
    00438                 *pWParam = 0x00;
    00439                 return TRUE;
    00440             }
    00441         }
    00442         if (IS_DBCS_ENABLED()) {
    00443             WORD wAnsi = LOWORD(dwAnsi);
    00444             //
    00445             // From:
    00446             //   HIBYTE(wAnsi)            = Dbcs TrailingByte.
    00447             //   LOBYTE(wAnsi)            = Dbcs LeadingByte or Sbcs character.
    00448             //
    00449             // To:
    00450             //   HIWORD(*pWParam)         = Original Data (information for DBCS messgaing).
    00451             //   HIBYTE(LOWORD(*pWParam)) = Dbcs LeadingByte Byte.
    00452             //   LOBYTE(LOWORD(*pWParam)) = Dbcs TrailingByte or Sbcs character.
    00453             //
    00454             if (IS_DBCS_MESSAGE(wAnsi)) {
    00455                 //
    00456                 // It's a DBCS character.
    00457                 //
    00458                 *pWParam = MAKEWPARAM(MAKEWORD(HIBYTE(wAnsi),LOBYTE(wAnsi)),HIWORD(*pWParam));
    00459             } else {
    00460                 //
    00461                 // It's a SBCS character.
    00462                 //
    00463                 *pWParam = MAKEWPARAM(MAKEWORD(LOBYTE(wAnsi),0),0);
    00464             }
    00465         } else {
    00466 #if DBG
    00467             if ((dwAnsi == 0) || (dwAnsi > 0xFF)) {
    00468                 RIPMSG1(RIP_VERBOSE, "msgW -> msgA: char = 0x%.4lX\n", dwAnsi);
    00469             }
    00470 #endif
    00471             *pWParam = dwAnsi;
    00472         }
    00473         break;
    00474     }
    00475
    00476     return TRUE;
    00477 }
    00478
    00479
    00480 /**************************************************************************\
    00481 * RtlMBMessageCharToWCS
    00482 *
    00483 * Converts a Multibyte character to a Wide character; in place
    00484 * Returns the number of characters converted or zero if failure
    00485 *
    00486 * 11-Feb-1992  JohnC    Created
    00487 * 13-Jan-1993  IanJa    Translate 2 characters (Publisher posts these!)
    00488 \**************************************************************************/
    00489
    00490 BOOL RtlMBMessageWParamCharToWCS(DWORD msg, WPARAM *pWParam)
    00491 {
    00492     DWORD dwUni;
    00493     NTSTATUS Status;
    00494     // FE_SB    (RtlMBMessageWParamCharToWCS)
    00495     BOOL  bWmCrIrDbcsChar = FALSE;
    00496     WORD  wAnsi = LOWORD(*pWParam);
    00497     // end FE_SB    (RtlMBMessageWParamCharToWCS)
    00498     WORD CodePage = THREAD_CODEPAGE();
    00499
    00500     /*
    00501      * Only these messages have CHARs: others are passed through
    00502      */
    00503
    00504     switch(msg) {
    00505     // FE_SB    (RtlMBMessageWParamCharToWCS)
    00506     case WM_CHAR:
    00507         //
    00508         // WM_CHAR's wParam format for WM_IME_REPORT:IR_DBCSCHAR
    00509         //
    00510         if (IS_DBCS_ENABLED() && (*pWParam & WMCR_IR_DBCSCHAR)) {
    00511             //
    00512             // Mark this message is sent as IR_DBCSCHAR format.
    00513             //
    00514             bWmCrIrDbcsChar = TRUE;
    00515         }
    00516
    00517         //
    00518         // Fall through....
    00519         //
    00520 #ifdef FE_IME
    00521     case WM_IME_CHAR:
    00522     case WM_IME_COMPOSITION:
    00523         //
    00524         // We need to re-align for Unicode convertsion..
    00525         // WM_CHAR/WM_IME_CHAR/WM_IME_COMPOSITION's wParam format :
    00526         //
    00527         // ReAlign IR_DBCS char format to regular sequence.
    00528         //
    00529         // From:
    00530         //
    00531         //  HIWORD(wParam)         = 0;
    00532         //  HIBYTE(LOWORD(wParam)) = DBCS LeadingByte.
    00533         //  LOBYTE(LOWORD(wParan)) = DBCS TrailingByte or SBCS character.
    00534         //
    00535         // To:
    00536         //  HIWORD(wParam)         = 0;
    00537         //  HIBYTE(LOWORD(wParam)) = DBCS TrailingByte.
    00538         //  LOBYTE(LOWORD(wParam)) = DBCS LeadingByte or SBCS character.
    00539         //
    00540         if (IS_DBCS_ENABLED()) {
    00541             *pWParam = MAKE_WPARAM_DBCSCHAR(wAnsi);
    00542         }
    00543 #endif
    00544         //
    00545         // Fall through...
    00546         //
    00547         // end FE_SB    (RtlMBMessageWParamCharToWCS)
    00548     case WM_CHARTOITEM:
    00549     case EM_SETPASSWORDCHAR:
    00550     case WM_DEADCHAR:
    00551     case WM_SYSCHAR:
    00552     case WM_SYSDEADCHAR:
    00553     case WM_MENUCHAR:
    00554
    00555         dwUni = 0;
    00556
    00557         if (IS_ACP(CodePage)) {
    00558             Status = RtlMultiByteToUnicodeN((LPWSTR)&dwUni, sizeof(dwUni),
    00559                     NULL, (LPSTR)pWParam, 2 * sizeof(CHAR));
    00560             if (!NT_SUCCESS(Status))
    00561                 return FALSE;
    00562         } else {
    00563             int cwch;
    00564 #ifdef _USERK_
    00565             cwch = EngMultiByteToWideChar(CodePage,
    00566                     (LPWSTR)&dwUni, sizeof(dwUni),
    00567                     (LPSTR)pWParam, 2);
    00568 #else
    00569             cwch = MultiByteToWideChar(CodePage, 0,
    00570                     (LPSTR)pWParam, 2,
    00571                     (LPWSTR)&dwUni, sizeof(dwUni) / sizeof(WCHAR));
    00572 #endif // _USERK_
    00573             // KdPrint(("0x%02x -> 0x%04x (%d)\n", *pWParam, dwUni, CodePage));
    00574             if (cwch == 0) {
    00575                 return FALSE;
    00576             }
    00577         }
    00578
    00579         // FE_SB    (RtlMBMessageWParamCharToWCS)
    00580         //
    00581         // if this character is sent for WM_IME_REPORT:IR_DBCSCHAR, we mark it.
    00582         //
    00583         if (bWmCrIrDbcsChar)
    00584             dwUni |= WMCR_IR_DBCSCHAR;
    00585         // else FE_SB (RtlMBMessageWParamCharToWCS)
    00586 #if DBG
    00587         if ((dwUni == 0) || (dwUni > 0xFF)) {
    00588             RIPMSG1(RIP_VERBOSE, "msgA -> msgW: wchar = 0x%lX\n", dwUni);
    00589         }
    00590 #endif
    00591         // end FE_SB
    00592         *pWParam = dwUni;
    00593         break;
    00594     }
    00595
    00596     return TRUE;
    00597 }
    00598
    00599 /**************************************************************************\
    00600 * RtlInitLargeAnsiString
    00601 *
    00602 * Captures a large ANSI string in the same manner as
    00603 * RtlInitAnsiString.
    00604 *
    00605 * 03-22-95 JimA         Created.
    00606 \**************************************************************************/
    00607
    00608 VOID RtlInitLargeAnsiString(
    00609     PLARGE_ANSI_STRING plstr,
    00610     LPCSTR psz,
    00611     UINT cchLimit)
    00612 {
    00613     ULONG Length;
    00614
    00615     plstr->Buffer = (PSTR)psz;
    00616     plstr->bAnsi = TRUE;
    00617     if (ARGUMENT_PRESENT( psz )) {
    00618         Length = strlen( psz );
    00619         plstr->Length = min(Length, cchLimit);
    00620         plstr->MaximumLength = min((Length + 1), cchLimit);
    00621     } else {
    00622         plstr->MaximumLength = 0;
    00623         plstr->Length = 0;
    00624     }
    00625 }
    00626
    00627 /**************************************************************************\
    00628 * RtlInitLargeUnicodeString
    00629 *
    00630 * Captures a large unicode string in the same manner as
    00631 * RtlInitUnicodeString.
    00632 *
    00633 * 03-22-95 JimA         Created.
    00634 \**************************************************************************/
    00635
    00636 VOID RtlInitLargeUnicodeString(
    00637     PLARGE_UNICODE_STRING plstr,
    00638     LPCWSTR psz,
    00639     UINT cchLimit)
    00640 {
    00641     ULONG Length;
    00642
    00643     plstr->Buffer = (PWSTR)psz;
    00644     plstr->bAnsi = FALSE;
    00645     if (ARGUMENT_PRESENT( psz )) {
    00646         Length = wcslen( psz ) * sizeof( WCHAR );
    00647         plstr->Length = min(Length, cchLimit);
    00648         plstr->MaximumLength = min((Length + sizeof(UNICODE_NULL)), cchLimit);
    00649     } else {
    00650         plstr->MaximumLength = 0;
    00651         plstr->Length = 0;
    00652     }
    00653 }
    00654