source: trunk/src/user32/win32wndhandle.cpp@ 8706

Last change on this file since 8706 was 8656, checked in by sandervl, 23 years ago

SetCustomWndHandleSemName added to override shared semaphore name used to synchronize global window handle array access (to avoid name clash with Odin)

File size: 3.9 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.14 2002-06-13 14:02:50 sandervl Exp $ */
2/*
3 * Win32 Handle Management Code for OS/2
4 *
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * TODO: The table should be dynamically increased when necessary
10 * This is just a quick and dirty implementation
11 * TODO: Probably need to clean up the table when app closes
12 * (also store PID and remove all handles with PID of terminating app)
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17
18#include <os2win.h>
19#include <vmutex.h>
20#include "win32wndhandle.h"
21#include <custombuild.h>
22
23#define DBG_LOCALLOG DBG_win32wndhandle
24#include "dbglocal.h"
25
26//******************************************************************************
27
28//Global DLL Data
29#pragma data_seg(_GLOBALDATA)
30ULONG WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
31CRITICAL_SECTION_OS2 globalwhandlecritsect = {0};
32ULONG lastIndex = 0;
33#pragma data_seg()
34
35static char *pszWndHandleSemName = NULL;
36
37//******************************************************************************
38//******************************************************************************
39void WIN32API SetCustomWndHandleSemName(LPSTR pszSemName)
40{
41 pszWndHandleSemName = pszSemName;
42}
43//******************************************************************************
44//******************************************************************************
45void InitializeWindowHandles()
46{
47 if(globalwhandlecritsect.hmtxLock == 0) {
48 DosInitializeCriticalSection(&globalwhandlecritsect, (pszWndHandleSemName) ? pszWndHandleSemName : WINHANDLE_CRITSECTION_NAME);
49 }
50 else {
51 dprintf(("InitializeWindowHandles -> access shared critical section"));
52 DosAccessCriticalSection(&globalwhandlecritsect, WINHANDLE_CRITSECTION_NAME);
53 }
54}
55//******************************************************************************
56//******************************************************************************
57BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
58{
59 DosEnterCriticalSection(&globalwhandlecritsect);
60
61 //find next free handle
62 if(lastIndex >= MAX_WINDOW_HANDLES-1) {
63 lastIndex = 0;
64 }
65 for(int i=lastIndex;i<MAX_WINDOW_HANDLES;i++) {
66 if(WindowHandleTable[i] == 0) {
67 lastIndex = i;
68 break;
69 }
70 }
71 if(i == MAX_WINDOW_HANDLES) {
72 //oops, out of handles
73 DosLeaveCriticalSection(&globalwhandlecritsect);
74 dprintf(("ERROR: USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
75 DebugInt3();
76 return FALSE;
77 }
78 *hwnd = lastIndex+1; //we skip handle 0x68000000
79 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
80 WindowHandleTable[lastIndex] = dwUserData;
81
82 lastIndex++;
83 DosLeaveCriticalSection(&globalwhandlecritsect);
84 dprintf2(("HwAllocateWindowHandle %x", *hwnd));
85 return TRUE;
86}
87//******************************************************************************
88//******************************************************************************
89void HwFreeWindowHandle(HWND hwnd)
90{
91 hwnd = hwnd - 1; //we skip handle 0x68000000
92 hwnd &= WNDHANDLE_MAGIC_MASK;
93 if(hwnd < MAX_WINDOW_HANDLES) {
94 DosEnterCriticalSection(&globalwhandlecritsect);
95 WindowHandleTable[hwnd] = 0;
96 DosLeaveCriticalSection(&globalwhandlecritsect);
97 }
98 dprintf2(("HwFreeWindowHandle %x", hwnd));
99}
100//******************************************************************************
101//******************************************************************************
102BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
103{
104 hwnd = hwnd - 1; //we skip handle 0x68000000
105 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
106 return FALSE; //unknown window (PM?)
107 }
108 hwnd &= WNDHANDLE_MAGIC_MASK;
109 if(hwnd < MAX_WINDOW_HANDLES) {
110 *pdwUserData = WindowHandleTable[hwnd];
111 return TRUE;
112 }
113 *pdwUserData = 0;
114 return FALSE;
115}
116//******************************************************************************
117//******************************************************************************
Note: See TracBrowser for help on using the repository browser.