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

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

Moved new user32 here

File size: 2.4 KB
Line 
1/* $Id: spy.cpp,v 1.6 1999-09-15 23:18:55 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
83#ifdef DEBUG
84BOOL PostSpyMessage(HWND hwnd, ULONG Msg, ULONG wParam, ULONG lParam)
85{
86 APIRET rc;
87
88 if (hqQueue == 0)
89 return FALSE;
90
91 pvdQMemory[msgIndex].hwnd = hwnd;
92 pvdQMemory[msgIndex].Msg = Msg;
93 pvdQMemory[msgIndex].wParam = wParam;
94 pvdQMemory[msgIndex].lParam = lParam;
95
96 if (rc = DosWriteQueue(hqQueue,
97 Q_SPYMSG_WNDMSG,
98 sizeof(Q_SPYMSG),
99 &pvdQMemory[msgIndex],
100 0))
101 {
102 hqQueue = 0; //give up, server probably died
103 dprintf(("PostSpyMessage: DosWriteQueue returned %d", rc));
104 return FALSE;
105 }
106 if(++msgIndex >= MAX_MESSAGES)
107 {
108 msgIndex = 0;
109 }
110 return TRUE;
111}
112
113#endif
Note: See TracBrowser for help on using the repository browser.