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
|
#include <windows.h>
#include <stdio.h>
#include <mmsystem.h>
typedef DWORD (WINAPI * MessagePtr)(UINT, UINT, DWORD, DWORD, DWORD);
#ifndef MMNOMIDI
typedef struct midiopenstrmid_tag
{
DWORD dwStreamID;
UINT uDeviceID;
} MIDIOPENSTRMID;
typedef struct midiopendesc_tag {
HMIDI hMidi;
DWORD_PTR dwCallback;
DWORD_PTR dwInstance;
DWORD_PTR dnDevNode;
DWORD cIds;
MIDIOPENSTRMID rgIds[1];
} MIDIOPENDESC;
typedef MIDIOPENDESC FAR *LPMIDIOPENDESC;
#endif // MMNOMIDI
#ifndef MODM_GETDEVCAPS
#define MODM_GETDEVCAPS 2
#endif
#ifndef MODM_OPEN
#define MODM_OPEN 3
#endif
#ifndef MODM_CLOSE
#define MODM_CLOSE 4
#endif
LONG testDriver()
{
HDRVR hdrvr;
DRVCONFIGINFO dci;
LONG lRes;
HMODULE lib;
DWORD modRet;
MIDIOUTCAPSA myCapsA;
MessagePtr modMessagePtr;
MIDIOPENDESC desc;
LONG totalClientNum = 0;
printf("Open...\n");
// Open the driver (no additional parameters needed this time).
if((hdrvr = OpenDriver(L".\\adlmididrv.dll", 0, 0)) == 0)
{
printf("!!! Can't open the driver\n");
return -1;
}
printf("Send DRV_QUERYCONFIGURE...\n");
// Make sure driver has a configuration dialog box.
if(SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
{
// Set the DRVCONFIGINFO structure and send the message
dci.dwDCISize = sizeof (dci);
dci.lpszDCISectionName = (LPWSTR)0;
dci.lpszDCIAliasName = (LPWSTR)0;
printf("Send DRV_CONFIGURE...\n");
lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LPARAM)&dci);
printf("<-- Got answer: %ld)\n", lRes);
}
else
{
printf("<-- No configure\n");
lRes = DRVCNF_OK;
}
printf("Getting library pointer\n");
if((lib = GetDriverModuleHandle(hdrvr)))
{
printf("Getting modMessage call\n");
modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
if(!modMessagePtr)
{
CloseDriver(hdrvr, 0, 0);
printf("!!! modMessage not found!\n");
return -1;
}
printf("Getting capabilities...\n");
modRet = modMessagePtr(0, MODM_GETDEVCAPS, (DWORD_PTR)NULL, (DWORD_PTR)&myCapsA, sizeof(myCapsA));
if(modRet != MMSYSERR_NOERROR)
{
CloseDriver(hdrvr, 0, 0);
printf("!!! modMessage returned an error!\n");
return -1;
}
printf("<-- %s\n", myCapsA.szPname);
printf("Trying to open driver\n");
ZeroMemory(&desc, sizeof(desc));
desc.dwInstance = (DWORD_PTR)hdrvr;
modRet = modMessagePtr(0, MODM_OPEN, (DWORD_PTR)&totalClientNum, (DWORD_PTR)&desc, sizeof(desc));
if(modRet != MMSYSERR_NOERROR)
{
CloseDriver(hdrvr, 0, 0);
printf("!!! modMessage returned an error!\n");
return -1;
}
printf("<-- Client Number: %ld\n", totalClientNum);
printf("Trying to close\n");
modRet = modMessagePtr(0, MODM_CLOSE, (DWORD_PTR)NULL, (DWORD_PTR)NULL, 0);
if(modRet != MMSYSERR_NOERROR)
{
CloseDriver(hdrvr, 0, 0);
printf("!!! modMessage returned an error!\n");
return -1;
}
}
else
{
CloseDriver(hdrvr, 0, 0);
printf("!!! Error when getting module handler!\n");
return -1;
}
printf("Close...\n");
// Close the driver (no additional parameters needed this time).
if(FAILED(CloseDriver(hdrvr, 0, 0)))
{
printf("!!! Error when closing\n");
return -1;
}
printf("Return...\n");
return 0;
}
int main()
{
LONG d = testDriver();
if(d == 0)
{
printf("TEST = OK\n");
return 0;
}
else
{
printf("TEST = FAILED\n");
return 1;
}
}
|