source: trunk/src/user32/resstring.cpp@ 121

Last change on this file since 121 was 121, checked in by sandervl, 26 years ago

Renamed .C to .CPP

File size: 3.9 KB
Line 
1/* $Id: resstring.cpp,v 1.1 1999-06-19 10:55:41 sandervl Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 */
8/*
9 * Win32 resource string functions for OS/2
10 *
11 * Copyright 1998 Sander van Leeuwen
12 *
13 */
14#define INCL_BASE
15#define INCL_WIN
16#define INCL_WINERRORS
17#define INCL_DOSFILEMGR
18#include <os2wrap.h> //Odin32 OS/2 api wrappers
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include "misc.h"
23#include "resstring.h"
24#include "win32util.h"
25#include "unicode.h"
26
27/******************************************************************************/
28//Strings stored as original: WORD len
29// UNICODE string (not null terminated)
30/******************************************************************************/
31int OS2LoadStringAscii(HINSTANCE hinst,
32 UINT wID,
33 LPSTR lpBuffer,
34 int cchBuffer)
35{
36 APIRET rc;
37 WCHAR *szbuf;
38 char modname[128];
39 HMODULE hmodule;
40
41 if(hinst != 0 && hinst != -1)
42 {
43 if(Win32QueryModuleName(hinst,
44 modname,
45 sizeof(modname)) == 0)
46 {
47 dprintf(("USER32: OS2LoadStringAscii: Can't determine handle of dll %08xh\n",
48 hinst));
49 return(0);
50 }
51
52 rc = DosQueryModuleHandle(modname,
53 &hmodule);
54 if(rc)
55 {
56 dprintf(("USER32: OS2LoadStringAscii: Can't determine handle of dll %s\n",
57 modname));
58
59 return(0);
60 }
61 }
62 else
63 hmodule = 0;
64
65 rc = DosGetResource(hmodule,
66 RT_RCDATA,
67 wID,
68 (PPVOID)&szbuf);
69 if(rc)
70 {
71 dprintf(("USER32: OS2LoadStringAscii failed with rc %08xh\n",
72 rc));
73
74 if(lpBuffer)
75 *lpBuffer = 0;
76
77 return(0); //TODO: SetLastError!
78 }
79
80 UnicodeToAsciiN(szbuf+1,
81 lpBuffer,
82 min((*szbuf), cchBuffer-1));
83
84 dprintf(("USER32: OS2LoadStringA retrieved string '%s' (size %d)\n",
85 lpBuffer,
86 (int)*szbuf));
87
88 DosFreeResource(szbuf);
89 return(strlen(lpBuffer)); //not including null terminator!
90}
91//******************************************************************************
92//******************************************************************************
93int OS2LoadStringUnicode(HINSTANCE hinst,
94 UINT wID,
95 WCHAR *lpBuffer,
96 int cchBuffer)
97{
98 APIRET rc;
99 WCHAR *szbuf;
100 char modname[128];
101 HMODULE hmodule;
102
103#ifdef DEBUG
104 char *astring;
105#endif
106
107 if(hinst != 0 && hinst != -1)
108 {
109 if(Win32QueryModuleName(hinst,
110 modname,
111 sizeof(modname)) == 0)
112 {
113 dprintf(("USER32: OS2LoadStringUnicode: Can't determine handle of dll %08xh\n",
114 hinst));
115 return(0);
116 }
117
118 rc = DosQueryModuleHandle(modname,
119 &hmodule);
120 if(rc)
121 {
122 dprintf(("USER32: OS2LoadStringUnicode: Can't determine handle of dll %s\n",
123 modname));
124
125 return(0);
126 }
127 }
128 else
129 hmodule = 0;
130
131 rc = DosGetResource(hmodule,
132 RT_RCDATA,
133 wID,
134 (PPVOID)&szbuf);
135 if(rc)
136 {
137 dprintf(("USER32: OS2LoadStringUnicode failed with rc %08xh\n",
138 rc));
139
140 if(lpBuffer)
141 *lpBuffer = 0;
142
143 return(0); //TODO: SetLastError!
144 }
145
146
147 memcpy(lpBuffer,
148 szbuf+1,
149 min((*szbuf), cchBuffer-1) * sizeof(WCHAR));
150
151 lpBuffer[min((*szbuf), cchBuffer-1)] = 0;
152
153#ifdef DEBUG
154 astring = UnicodeToAsciiString(lpBuffer);
155 WriteLog("USER32: OS2LoadStringUnicode retrieved string '%s' of size %d\n",
156 astring,
157 (int)*szbuf);
158 FreeAsciiString(astring);
159#endif
160
161 DosFreeResource(szbuf);
162 return(UniStrlen(lpBuffer)); //not including null terminator!
163}
164
Note: See TracBrowser for help on using the repository browser.