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

Last change on this file since 3101 was 3101, checked in by sandervl, 25 years ago

replaced os2.h includes by os2wrap.h

File size: 2.4 KB
Line 
1/* $Id: spy.cpp,v 1.11 2000-03-13 13:10:48 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 <os2wrap.h>
19
20#include <stdlib.h>
21#include <stddef.h>
22#include <string.h>
23#include <misc.h>
24#include <spy.h>
25
26#define DBG_LOCALLOG DBG_spy
27#include "dbglocal.h"
28
29#define Q_BUFFER_SIZE 4096
30#define MAX_MESSAGES (Q_BUFFER_SIZE/sizeof(Q_SPYMSG))
31
32PID pidServer = 0;
33HQUEUE hqQueue = 0;
34Q_SPYMSG *pvdQMemory = 0;
35int msgIndex = 0;
36
37BOOL InitSpyQueue()
38{
39 APIRET rc;
40
41 if ((rc = DosOpenQueue(&pidServer, &hqQueue, "\\queues\\"Q_NAME)) != 0)
42 {
43 dprintf(("InitSpyQueue: couldn't open spy queue rc=%d!", rc));
44 return FALSE;
45 }
46 if ((rc = DosAllocSharedMem((VOID **)&pvdQMemory,
47 NULL,
48 Q_BUFFER_SIZE,
49 fALLOCSHR)) != 0)
50 {
51 dprintf(("InitSpyQueue: DosAllocSharedMem failed rc=%d", rc));
52 DosCloseQueue(hqQueue);
53 return FALSE;
54 }
55
56 /* give memory to server */
57 if (DosGiveSharedMem(pvdQMemory, pidServer, PAG_READ | PAG_WRITE))
58 {
59 dprintf(("InitSpyQueue: DosGiveSharedMem failed"));
60 DosCloseQueue(hqQueue);
61 return FALSE;
62 }
63 return (TRUE);
64}
65
66void CloseSpyQueue()
67{
68 APIRET rc;
69
70 dprintf(("CloseSpyQueue"));
71 if(hqQueue) {
72 if(pvdQMemory) {
73 rc = DosWriteQueue(hqQueue, Q_SPYMSG_KILLSERVER, 0, 0, 0);
74 if(rc) {
75 dprintf(("CloseSpyQueue: DosWriteQueue returned %d", rc));
76 }
77 }
78 DosCloseQueue(hqQueue);
79 }
80 if(pvdQMemory)
81 DosFreeMem(pvdQMemory);
82}
83
84#ifdef DEBUG
85BOOL PostSpyMessage(HWND hwnd, ULONG Msg, ULONG wParam, ULONG lParam)
86{
87 APIRET rc;
88
89 if (hqQueue == 0)
90 return FALSE;
91
92 pvdQMemory[msgIndex].hwnd = hwnd;
93 pvdQMemory[msgIndex].Msg = Msg;
94 pvdQMemory[msgIndex].wParam = wParam;
95 pvdQMemory[msgIndex].lParam = lParam;
96
97 if ((rc = DosWriteQueue(hqQueue,
98 Q_SPYMSG_WNDMSG,
99 sizeof(Q_SPYMSG),
100 &pvdQMemory[msgIndex],
101 0)) != 0)
102 {
103 hqQueue = 0; //give up, server probably died
104 dprintf(("PostSpyMessage: DosWriteQueue returned %d", rc));
105 return FALSE;
106 }
107 if(++msgIndex >= MAX_MESSAGES)
108 {
109 msgIndex = 0;
110 }
111 return TRUE;
112}
113
114#endif
Note: See TracBrowser for help on using the repository browser.