source: trunk/src/user32/spy.cpp@ 225

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

Message handler updates & bugfixes

File size: 2.3 KB
Line 
1/* $Id: spy.cpp,v 1.3 1999-06-27 16:23:23 sandervl Exp $ */
2
3/*
4 * Queue procedures to send messages to the spy server
5 *
6 * Copyright 1999 Sander van Leeuwen
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_DOSPROCESS
13#define INCL_DOSQUEUES
14#define INCL_DOSMEMMGR
15#define INCL_WINMESSAGEMGR
16#define INCL_DOSERRORS
17#define INCL_DOSSEMAPHORES
18#include <os2.h>
19#include <os2wrap.h>
20
21#include <stdlib.h>
22#include <stddef.h>
23#include <string.h>
24#include <misc.h>
25#include <spy.h>
26
27
28#define Q_BUFFER_SIZE 4096
29#define MAX_MESSAGES (Q_BUFFER_SIZE/sizeof(Q_SPYMSG))
30
31PID pidServer = 0;
32HQUEUE hqQueue = 0;
33Q_SPYMSG *pvdQMemory = 0;
34int msgIndex = 0;
35
36BOOL InitSpyQueue()
37{
38 APIRET rc;
39
40 if (rc = DosOpenQueue(&pidServer, &hqQueue, "\\queues\\"Q_NAME))
41 {
42 dprintf(("InitSpyQueue: couldn't open spy queue rc=%d!", rc));
43 return FALSE;
44 }
45 if (rc = DosAllocSharedMem((VOID **)&pvdQMemory,
46 NULL,
47 Q_BUFFER_SIZE,
48 fALLOCSHR))
49 {
50 dprintf(("InitSpyQueue: DosAllocSharedMem failed rc=%d", rc));
51 DosCloseQueue(hqQueue);
52 return FALSE;
53 }
54
55 /* give memory to server */
56 if (DosGiveSharedMem(pvdQMemory, pidServer, PAG_READ | PAG_WRITE))
57 {
58 dprintf(("InitSpyQueue: DosGiveSharedMem failed"));
59 DosCloseQueue(hqQueue);
60 return FALSE;
61 }
62 return (TRUE);
63}
64
65void CloseSpyQueue()
66{
67 APIRET rc;
68
69 dprintf(("CloseSpyQueue"));
70 if(hqQueue) {
71 if(pvdQMemory) {
72 rc = DosWriteQueue(hqQueue, Q_SPYMSG_KILLSERVER, 0, 0, 0);
73 if(rc) {
74 dprintf(("CloseSpyQueue: DosWriteQueue returned %d", rc));
75 }
76 }
77 DosCloseQueue(hqQueue);
78 }
79 if(pvdQMemory)
80 DosFreeMem(pvdQMemory);
81}
82
83BOOL PostSpyMessage(HWND hwnd, ULONG Msg, ULONG wParam, ULONG lParam)
84{
85 APIRET rc;
86
87 if (hqQueue == 0)
88 return FALSE;
89
90 pvdQMemory[msgIndex].hwnd = hwnd;
91 pvdQMemory[msgIndex].Msg = Msg;
92 pvdQMemory[msgIndex].wParam = wParam;
93 pvdQMemory[msgIndex].lParam = lParam;
94
95 if (rc = DosWriteQueue(hqQueue,
96 Q_SPYMSG_WNDMSG,
97 sizeof(Q_SPYMSG),
98 &pvdQMemory[msgIndex],
99 0))
100 {
101 hqQueue = 0; //give up, server probably died
102 dprintf(("PostSpyMessage: DosWriteQueue returned %d", rc));
103 return FALSE;
104 }
105 if(++msgIndex >= MAX_MESSAGES)
106 {
107 msgIndex = 0;
108 }
109 return TRUE;
110}
111
Note: See TracBrowser for help on using the repository browser.