source: trunk/src/user32/RESSTRING.C@ 91

Last change on this file since 91 was 83, checked in by phaller, 26 years ago

Fix: various unicode fixes

File size: 3.8 KB
Line 
1/*
2 *
3 * Project Odin Software License can be found in LICENSE.TXT
4 *
5 */
6/*
7 * Win32 resource string functions for OS/2
8 *
9 * Copyright 1998 Sander van Leeuwen
10 *
11 */
12#define INCL_BASE
13#define INCL_WIN
14#define INCL_WINERRORS
15#define INCL_DOSFILEMGR
16#include <os2.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include "misc.h"
21#include "resstring.h"
22#include "win32util.h"
23#include "unicode.h"
24
25/******************************************************************************/
26//Strings stored as original: WORD len
27// UNICODE string (not null terminated)
28/******************************************************************************/
29int OS2LoadStringAscii(HINSTANCE hinst,
30 UINT wID,
31 LPSTR lpBuffer,
32 int cchBuffer)
33{
34 APIRET rc;
35 WCHAR *szbuf;
36 char modname[128];
37 HMODULE hmodule;
38
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 }
59 }
60 else
61 hmodule = 0;
62
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!
76 }
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
86 DosFreeResource(szbuf);
87 return(strlen(lpBuffer)); //not including null terminator!
88}
89//******************************************************************************
90//******************************************************************************
91int OS2LoadStringUnicode(HINSTANCE hinst,
92 UINT wID,
93 WCHAR *lpBuffer,
94 int cchBuffer)
95{
96 APIRET rc;
97 WCHAR *szbuf;
98 char modname[128];
99 HMODULE hmodule;
100
101#ifdef DEBUG
102 char *astring;
103#endif
104
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 }
125 }
126 else
127 hmodule = 0;
128
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!
142 }
143
144
145 memcpy(lpBuffer,
146 szbuf+1,
147 min((*szbuf), cchBuffer-1) * sizeof(WCHAR));
148
149 lpBuffer[min((*szbuf), cchBuffer-1)] = 0;
150
151#ifdef DEBUG
152 astring = UnicodeToAsciiString(lpBuffer);
153 WriteLog("USER32: OS2LoadStringUnicode retrieved string '%s' of size %d\n",
154 astring,
155 (int)*szbuf);
156 FreeAsciiString(astring);
157#endif
158
159 DosFreeResource(szbuf);
160 return(UniStrlen(lpBuffer)); //not including null terminator!
161}
162
Note: See TracBrowser for help on using the repository browser.