source: trunk/src/kernel32/os2util.cpp@ 120

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

Include os2wrap.h instead of os2.h

File size: 6.4 KB
Line 
1/* $Id: os2util.cpp,v 1.3 1999-06-19 10:54:42 sandervl Exp $ */
2
3/*
4 * Misc util. procedures
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1998 Peter FitzSimmons
8 * Copyright 1998 Patrick Haller
9 *
10 *
11 * Project Odin Software License can be found in LICENSE.TXT
12 *
13 */
14#define INCL_BASE
15#define INCL_DOSPROCESS
16#include <os2wrap.h> //Odin32 OS/2 api wrappers
17#include <string.h>
18#include <stdlib.h>
19#include <stdio.h> /*PLF Wed 98-03-18 05:15:04*/
20#include <malloc.h> /*PLF Wed 98-03-18 05:15:04*/
21#include "os2util.h"
22#include "misc.h"
23#include "version.h"
24
25/***********************************
26 * PH: fixups for missing os2win.h *
27 ***********************************/
28
29void _System SetLastError(ULONG ulError);
30
31//******************************************************************************
32//******************************************************************************
33void OS2SetExitList(unsigned long handler)
34{
35 APIRET rc;
36
37 rc = DosExitList(EXLST_ADD | 0x00002A00, (PFNEXITLIST)handler);
38 if(rc) {
39 dprintf(("DosExitList returned %d\n", rc));
40 }
41}
42//******************************************************************************
43//******************************************************************************
44void OS2ClearExitList()
45{
46 DosExitList(EXLST_EXIT, NULL);
47}
48//******************************************************************************
49//******************************************************************************
50void OS2RemoveExitList(unsigned long handler)
51{
52 DosExitList(EXLST_REMOVE, (PFNEXITLIST)handler);
53}
54//******************************************************************************
55//TODO: not reentrant!
56//******************************************************************************
57char *OS2GetDllName(ULONG hModule)
58{
59 static char modname[CCHMAXPATH] = {0};
60
61 DosQueryModuleName(hModule, CCHMAXPATH, modname);
62 return(modname);
63}
64//******************************************************************************
65void SYSTEM CheckVersion(ULONG version, char *modname)
66{
67 dprintf(("CheckVersion of %s, %d\n", modname, version));
68 if(version != PE2LX_VERSION){
69 static char msg[300];
70 int r;
71 dprintf(("Version mismatch! %d, %d: %s\n", version, PE2LX_VERSION, modname));
72 sprintf(msg, "%s is intended for use with a different release of PE2LX.\n", modname);
73 do{
74 r = WinMessageBox(HWND_DESKTOP, NULLHANDLE, msg, "Version Mismatch!", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE);
75 }while(r == MBID_RETRY); // giggle
76 if( r != MBID_IGNORE )
77 exit(987);
78 }
79}
80
81void SYSTEM CheckVersionFromHMOD(ULONG version, HMODULE hModule)
82{
83 char name[_MAX_PATH];
84
85 // query name of dll.
86 if(!DosQueryModuleName(hModule, sizeof(name), name))
87 CheckVersion(version, name);
88}
89
90/*****************************************************************************
91 * Name : HMODULE OS2iGetModuleHandleA
92 * Purpose : replacement for IBM Open32's GetModuleHandle
93 * Parameters: LPCTSTR lpszModule
94 * Variables :
95 * Result : HMODULE hModule or NULLHANDLE in case of error
96 * Remark :
97 * Status : REWRITTEN UNTESTED
98 *
99 * Author : Patrick Haller [Sun, 1998/04/04 01:55]
100 *****************************************************************************/
101
102HMODULE OS2iGetModuleHandleA(PSZ pszModule)
103{
104 HMODULE hModule; /* module handle */
105 APIRET rc; /* API returncode */
106 static HMODULE hModuleExe; /* "cached" hModuleExe */
107 PTIB pTIB; /* parameters for DosGetInfoBlocks */
108 PPIB pPIB;
109
110 dprintf(("KERNEL32:GetModuleHandle(%s)\n",
111 pszModule));
112
113 /* @@@PH 98/04/04
114
115 this Open32 function is broken for pszModule == NULL
116 return(GetModuleHandle(pszModule));
117
118 Open32 always returns -1 here, however it should return the handle
119 of the current process. MFC30 crashes.
120
121 SvL, me thinks for PELDR support, you'll have to rewrite
122 this code anyway :)
123
124 */
125
126 if (NULL == pszModule) /* obtain handle to current executable */
127 {
128 if (hModuleExe != NULLHANDLE) /* do we have a cached handle ? */
129 return (hModuleExe);
130
131 rc = DosGetInfoBlocks(&pTIB, /* get the info blocks */
132 &pPIB);
133 if (rc != NO_ERROR) /* check for errors */
134 {
135 SetLastError(rc); /* set error code */
136 return (NULLHANDLE); /* signal failure */
137 }
138
139 hModuleExe = pPIB->pib_hmte; /* set cached module */
140 hModule = pPIB->pib_hmte; /* module table entry ID */
141 }
142 else
143 {
144 rc = DosQueryModuleHandle(pszModule, /* query module handle */
145 &hModule);
146
147 if (rc != NO_ERROR) /* check for errors */
148 {
149 SetLastError(rc); /* set error code */
150 return (NULLHANDLE); /* signal failure */
151 }
152 }
153
154 return (hModule); /* return determined handle */
155}
156
157
158HMODULE OS2QueryModuleHandle(char *modname)
159{
160 HMODULE hModule;
161 APIRET rc;
162
163 rc = DosQueryModuleHandle(modname, /* query module handle */
164 &hModule);
165 if(rc)
166 return(-1);
167
168 return(hModule);
169}
170
171//SvL: only for RT_RCDATA!
172ULONG OS2GetResourceSize(HMODULE hinstance, int id)
173{
174 APIRET rc;
175 ULONG size;
176
177 rc = DosQueryResourceSize(hinstance, RT_RCDATA, id, &size);
178 if(rc) {
179 dprintf(("DosQueryResourceSize returned %d, %X id = %d\n", rc, hinstance, id));
180 return(0);
181 }
182 return(size);
183}
184
185BOOL OS2GetResource(HMODULE hinstance, int id, char *destbuf, int bufLength)
186{
187 APIRET rc;
188 char *resdata;
189 ULONG size;
190
191 rc = DosQueryResourceSize(hinstance, RT_RCDATA, id, &size);
192 if(rc) {
193 dprintf(("OS2GetResource: Can't get resource size of %d!!!\n", id));
194 return(0);
195 }
196 rc = DosGetResource(hinstance, RT_RCDATA, id, (PPVOID)&resdata);
197 if(rc) {
198 dprintf(("OS2GetResource: Can't find resource %d!!!\n", id));
199 return(0);
200 }
201 dprintf(("OS2GetResoure: bufLength %d, size %d, id %d", bufLength, size, id));
202 size = min(size, bufLength);
203 memcpy(destbuf, resdata, size);
204 DosFreeResource(resdata);
205
206 return(FALSE);
207}
208
209
210
211
212void OS2Wait(ULONG msec)
213{
214 DosSleep(msec);
215}
Note: See TracBrowser for help on using the repository browser.