This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drvproc.cpp
172 lines (150 loc) · 5.92 KB
/
drvproc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// From Ben Rudiak-Gould's huffyuv
#include "codec_inst.h"
/***************************************************************************
* DriverProc - The entry point for an installable driver.
*
* PARAMETERS
* dwDriverId: For most messages, <dwDriverId> is the DWORD
* value that the driver returns in response to a <DRV_OPEN> message.
* Each time that the driver is opened, through the <DrvOpen> API,
* the driver receives a <DRV_OPEN> message and can return an
* arbitrary, non-zero value. The installable driver interface
* saves this value and returns a unique driver handle to the
* application. Whenever the application sends a message to the
* driver using the driver handle, the interface routes the message
* to this entry point and passes the corresponding <dwDriverId>.
* This mechanism allows the driver to use the same or different
* identifiers for multiple opens but ensures that driver handles
* are unique at the application interface layer.
*
* The following messages are not related to a particular open
* instance of the driver. For these messages, the dwDriverId
* will always be zero.
*
* DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
*
* hDriver: This is the handle returned to the application by the
* driver interface.
*
* uiMessage: The requested action to be performed. Message
* values below <DRV_RESERVED> are used for globally defined messages.
* Message values from <DRV_RESERVED> to <DRV_USER> are used for
* defined driver protocols. Messages above <DRV_USER> are used
* for driver specific messages.
*
* lParam1: Data for this message. Defined separately for
* each message
*
* lParam2: Data for this message. Defined separately for
* each message
*
* RETURNS
* Defined separately for each message.
*
***************************************************************************/
LRESULT WINAPI DriverProc(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
{
CodecInst* pCodecInst = (CodecInst*)(UINT)dwDriverID;
switch (uiMessage)
{
case DRV_LOAD:
return (LRESULT)1L;
case DRV_FREE:
return (LRESULT)1L;
case DRV_OPEN:
return (LRESULT)(DWORD)(UINT) Open((ICOPEN*) lParam2);
case DRV_CLOSE:
{
if (pCodecInst)
{
Close(pCodecInst);
}
return (LRESULT)1L;
}
/*********************************************************************
compression messages
*********************************************************************/
case ICM_COMPRESS_QUERY:
return pCodecInst->CompressQuery((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_COMPRESS_BEGIN:
return pCodecInst->CompressBegin((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_COMPRESS_GET_FORMAT:
return pCodecInst->CompressGetFormat((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_COMPRESS_GET_SIZE:
return pCodecInst->CompressGetSize((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_COMPRESS:
return pCodecInst->Compress((ICCOMPRESS*)lParam1, (DWORD)lParam2);
case ICM_COMPRESS_END:
return pCodecInst->CompressEnd();
/*********************************************************************
decompress messages
*********************************************************************/
case ICM_DECOMPRESS_QUERY:
return pCodecInst->DecompressQuery((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_DECOMPRESS_BEGIN:
return pCodecInst->DecompressBegin((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_DECOMPRESS_GET_FORMAT:
return pCodecInst->DecompressGetFormat((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_DECOMPRESS_GET_PALETTE:
return pCodecInst->DecompressGetPalette((LPBITMAPINFOHEADER)lParam1, (LPBITMAPINFOHEADER)lParam2);
case ICM_DECOMPRESS:
return pCodecInst->Decompress((ICDECOMPRESS*)lParam1);
case ICM_DECOMPRESS_END:
return pCodecInst->DecompressEnd();
/*********************************************************************
state messages
*********************************************************************/
case DRV_QUERYCONFIGURE:
return (LRESULT)1L;
case DRV_CONFIGURE:
{
pCodecInst->Configure((HWND)lParam1);
return DRV_OK;
}
case ICM_CONFIGURE:
return (lParam1 == -1) ? ICERR_OK : pCodecInst->Configure((HWND)lParam1);
case ICM_ABOUT:
return ICERR_UNSUPPORTED;
case ICM_GETSTATE:
return pCodecInst->GetState((LPVOID)lParam1, (DWORD)lParam2);
case ICM_SETSTATE:
return pCodecInst->SetState((LPVOID)lParam1, (DWORD)lParam2);
case ICM_GETINFO:
return pCodecInst->GetInfo((ICINFO*)lParam1, (DWORD)lParam2);
case ICM_GETDEFAULTQUALITY:
{
if (lParam1)
{
*((LPDWORD)lParam1) = ICQUALITY_HIGH;
return ICERR_OK;
}
break;
}
/*********************************************************************
standard driver messages
*********************************************************************/
case DRV_DISABLE:
case DRV_ENABLE:
return (LRESULT)1L;
case DRV_INSTALL:
case DRV_REMOVE:
return (LRESULT)DRV_OK;
}
#ifndef PROFILER
if (uiMessage < DRV_USER)
{
return DefDriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
}
else
{
return ICERR_UNSUPPORTED;
#else
return ICERR_UNSUPPORTED;
#endif
}
}
void WINAPI ShowConfiguration(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
CodecInst codecInst;
codecInst.Configure(hwnd);
}