Changeset 83 for trunk/src/user32


Ignore:
Timestamp:
Jun 9, 1999, 10:16:53 PM (26 years ago)
Author:
phaller
Message:

Fix: various unicode fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/RESSTRING.C

    r46 r83  
    2323#include "unicode.h"
    2424
    25 static char *UnicodeToAsciiN(WCHAR *wstring, char *astring, int maxlen);
    26 
    2725/******************************************************************************/
    28 //Strings stored as original: WORD    len 
     26//Strings stored as original: WORD    len
    2927//                            UNICODE string (not null terminated)
    3028/******************************************************************************/
    31 int OS2LoadStringAscii(HINSTANCE hinst, UINT wID, LPSTR lpBuffer, int cchBuffer)
     29int OS2LoadStringAscii(HINSTANCE hinst,
     30                       UINT      wID,
     31                       LPSTR     lpBuffer,
     32                       int       cchBuffer)
    3233{
    33  APIRET  rc;
    34  WCHAR  *szbuf;
    35  char    modname[128];
    36  HMODULE hmodule;
     34  APIRET  rc;
     35  WCHAR  *szbuf;
     36  char    modname[128];
     37  HMODULE hmodule;
    3738
    38   if(hinst != 0 && hinst != -1) {
    39         if(Win32QueryModuleName(hinst, modname, sizeof(modname)) == 0) {
    40 #ifdef DEBUG
    41                 WriteLog("Can't determine handle of dll %X\n", hinst);
    42 #endif
    43                 return(0);
    44         }
    45         rc = DosQueryModuleHandle(modname, &hmodule);
    46         if(rc) {
    47 #ifdef DEBUG
    48                 WriteLog("Can't determine handle of dll %s\n", modname);
    49 #endif
    50                 return(0);
    51         }
     39  if(hinst != 0 && hinst != -1)
     40  {
     41    if(Win32QueryModuleName(hinst,
     42                            modname,
     43                            sizeof(modname)) == 0)
     44    {
     45      dprintf(("USER32: OS2LoadStringAscii: Can't determine handle of dll %08xh\n",
     46               hinst));
     47      return(0);
     48   }
     49
     50   rc = DosQueryModuleHandle(modname,
     51                             &hmodule);
     52   if(rc)
     53   {
     54     dprintf(("USER32: OS2LoadStringAscii: Can't determine handle of dll %s\n",
     55              modname));
     56
     57     return(0);
     58   }
    5259  }
    53   else  hmodule = 0;
     60  else
     61    hmodule = 0;
    5462
    55   rc = DosGetResource(hmodule, RT_RCDATA, wID, (PPVOID)&szbuf);
    56   if(rc) {
    57 #ifdef DEBUG
    58         WriteLog("OS2LoadString failed with rc %d\n", rc);
    59 #endif
    60         if(lpBuffer)    *lpBuffer = 0;
    61         return(0);      //TODO: SetLastError!
     63  rc = DosGetResource(hmodule,
     64                      RT_RCDATA,
     65                      wID,
     66                      (PPVOID)&szbuf);
     67  if(rc)
     68  {
     69    dprintf(("USER32: OS2LoadStringAscii failed with rc %08xh\n",
     70             rc));
     71
     72    if(lpBuffer)
     73      *lpBuffer = 0;
     74
     75    return(0);  //TODO: SetLastError!
    6276  }
    63   UnicodeToAsciiN(szbuf+1, lpBuffer, min((*szbuf), cchBuffer-1));
    64 #ifdef DEBUG
    65   WriteLog("OS2LoadString retrieved string '%s' (size %d)\n", lpBuffer, (int)*szbuf);
    66 #endif
     77
     78  UnicodeToAsciiN(szbuf+1,
     79                  lpBuffer,
     80                  min((*szbuf), cchBuffer-1));
     81
     82  dprintf(("USER32: OS2LoadStringA retrieved string '%s' (size %d)\n",
     83           lpBuffer,
     84           (int)*szbuf));
     85
    6786  DosFreeResource(szbuf);
    68   return(strlen(lpBuffer));     //not including null terminator!
     87  return(strlen(lpBuffer));              //not including null terminator!
    6988}
    7089//******************************************************************************
    7190//******************************************************************************
    72 int OS2LoadStringUnicode(HINSTANCE hinst, UINT wID, WCHAR *lpBuffer, int cchBuffer)
     91int OS2LoadStringUnicode(HINSTANCE hinst,
     92                         UINT      wID,
     93                         WCHAR     *lpBuffer,
     94                         int       cchBuffer)
    7395{
    74  APIRET  rc;
    75  WCHAR  *szbuf;
    76  char    modname[128];
    77  HMODULE hmodule;
     96  APIRET  rc;
     97  WCHAR  *szbuf;
     98  char    modname[128];
     99  HMODULE hmodule;
     100
    78101#ifdef DEBUG
    79102 char   *astring;
    80103#endif
    81104
    82   if(hinst != 0 && hinst != -1) {
    83         if(Win32QueryModuleName(hinst, modname, sizeof(modname)) == 0) {
    84 #ifdef DEBUG
    85                 WriteLog("Can't determine handle of dll %X\n", hinst);
    86 #endif
    87                 return(0);
    88         }
    89         rc = DosQueryModuleHandle(modname, &hmodule);
    90         if(rc) {
    91 #ifdef DEBUG
    92                 WriteLog("Can't determine handle of dll %s\n", modname);
    93 #endif
    94                 return(0);
    95         }
     105  if(hinst != 0 && hinst != -1)
     106  {
     107    if(Win32QueryModuleName(hinst,
     108                            modname,
     109                            sizeof(modname)) == 0)
     110    {
     111      dprintf(("USER32: OS2LoadStringUnicode: Can't determine handle of dll %08xh\n",
     112               hinst));
     113      return(0);
     114   }
     115
     116   rc = DosQueryModuleHandle(modname,
     117                             &hmodule);
     118   if(rc)
     119   {
     120     dprintf(("USER32: OS2LoadStringUnicode: Can't determine handle of dll %s\n",
     121              modname));
     122
     123     return(0);
     124   }
    96125  }
    97   else  hmodule = 0;
     126  else
     127    hmodule = 0;
    98128
    99   rc = DosGetResource(hmodule, RT_RCDATA, wID, (PPVOID)&szbuf);
    100   if(rc) {
    101 #ifdef DEBUG
    102         WriteLog("OS2LoadString failed with rc %d\n", rc);
    103 #endif
    104         if(lpBuffer)    *lpBuffer = 0;
    105         return(0);      //TODO: SetLastError!
     129  rc = DosGetResource(hmodule,
     130                      RT_RCDATA,
     131                      wID,
     132                      (PPVOID)&szbuf);
     133  if(rc)
     134  {
     135    dprintf(("USER32: OS2LoadStringUnicode failed with rc %08xh\n",
     136             rc));
     137
     138    if(lpBuffer)
     139      *lpBuffer = 0;
     140
     141    return(0);  //TODO: SetLastError!
    106142  }
    107   memcpy(lpBuffer, szbuf+1, min((*szbuf), cchBuffer-1)*sizeof(WCHAR));
     143
     144
     145  memcpy(lpBuffer,
     146         szbuf+1,
     147         min((*szbuf), cchBuffer-1) * sizeof(WCHAR));
     148
    108149  lpBuffer[min((*szbuf), cchBuffer-1)] = 0;
    109150
    110151#ifdef DEBUG
    111152  astring = UnicodeToAsciiString(lpBuffer);
    112   WriteLog("OS2LoadStringW retrieved string '%s' of size %d\n", astring, (int)*szbuf);
     153  WriteLog("USER32: OS2LoadStringUnicode retrieved string '%s' of size %d\n",
     154           astring,
     155           (int)*szbuf);
    113156  FreeAsciiString(astring);
    114157#endif
     158
    115159  DosFreeResource(szbuf);
    116   return(UniStrlen(lpBuffer));  //not including null terminator!
     160  return(UniStrlen(lpBuffer));           //not including null terminator!
    117161}
    118 //******************************************************************************
    119 //******************************************************************************
    120 static char *UnicodeToAsciiN(WCHAR *wstring, char *astring, int maxlen)
    121 {
    122  int i;
    123162
    124   for(i=0;i<maxlen;i++) {
    125         astring[i] = (UCHAR)wstring[i];
    126   }
    127   astring[maxlen] = 0;
    128   return(astring);
    129 }
    130 /******************************************************************************/
    131 /******************************************************************************/
    132 
Note: See TracChangeset for help on using the changeset viewer.