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

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

* empty log message *

File size: 3.5 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
25static char *UnicodeToAsciiN(WCHAR *wstring, char *astring, int maxlen);
26
27/******************************************************************************/
28//Strings stored as original: WORD len
29// UNICODE string (not null terminated)
30/******************************************************************************/
31int OS2LoadStringAscii(HINSTANCE hinst, UINT wID, LPSTR lpBuffer, int cchBuffer)
32{
33 APIRET rc;
34 WCHAR *szbuf;
35 char modname[128];
36 HMODULE hmodule;
37
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 }
52 }
53 else hmodule = 0;
54
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!
62 }
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
67 DosFreeResource(szbuf);
68 return(strlen(lpBuffer)); //not including null terminator!
69}
70//******************************************************************************
71//******************************************************************************
72int OS2LoadStringUnicode(HINSTANCE hinst, UINT wID, WCHAR *lpBuffer, int cchBuffer)
73{
74 APIRET rc;
75 WCHAR *szbuf;
76 char modname[128];
77 HMODULE hmodule;
78#ifdef DEBUG
79 char *astring;
80#endif
81
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 }
96 }
97 else hmodule = 0;
98
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!
106 }
107 memcpy(lpBuffer, szbuf+1, min((*szbuf), cchBuffer-1)*sizeof(WCHAR));
108 lpBuffer[min((*szbuf), cchBuffer-1)] = 0;
109
110#ifdef DEBUG
111 astring = UnicodeToAsciiString(lpBuffer);
112 WriteLog("OS2LoadStringW retrieved string '%s' of size %d\n", astring, (int)*szbuf);
113 FreeAsciiString(astring);
114#endif
115 DosFreeResource(szbuf);
116 return(UniStrlen(lpBuffer)); //not including null terminator!
117}
118//******************************************************************************
119//******************************************************************************
120static char *UnicodeToAsciiN(WCHAR *wstring, char *astring, int maxlen)
121{
122 int i;
123
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 TracBrowser for help on using the repository browser.