5 #define ASIODRV_DESC "description"
6 #define INPROC_SERVER "InprocServer32"
7 #define ASIO_PATH "software\\asio"
8 #define COM_CLSID "clsid"
10 // ******************************************************************
12 // ******************************************************************
13 static LONG
findDrvPath (char *clsidstr
,char *dllpath
,int dllpathsize
)
15 HKEY hkEnum
,hksub
,hkpath
;
18 DWORD datatype
,datasize
;
25 CharLowerBuffA(clsidstr
,strlen(clsidstr
));
26 if ((cr
= RegOpenKeyA(HKEY_CLASSES_ROOT
,COM_CLSID
,&hkEnum
)) == ERROR_SUCCESS
) {
29 while (cr
== ERROR_SUCCESS
&& !found
) {
30 cr
= RegEnumKeyA(hkEnum
,index
++,databuf
,512);
31 if (cr
== ERROR_SUCCESS
) {
32 CharLowerBuffA(databuf
,strlen(databuf
));
33 if (!(strcmp(databuf
,clsidstr
))) {
34 if ((cr
= RegOpenKeyExA(hkEnum
,databuf
,0,KEY_READ
,&hksub
)) == ERROR_SUCCESS
) {
35 if ((cr
= RegOpenKeyExA(hksub
,INPROC_SERVER
,0,KEY_READ
,&hkpath
)) == ERROR_SUCCESS
) {
36 datatype
= REG_SZ
; datasize
= (DWORD
)dllpathsize
;
37 cr
= RegQueryValueEx(hkpath
,0,0,&datatype
,(LPBYTE
)dllpath
,&datasize
);
38 if (cr
== ERROR_SUCCESS
) {
39 memset(&ofs
,0,sizeof(OFSTRUCT
));
40 ofs
.cBytes
= sizeof(OFSTRUCT
);
41 hfile
= OpenFile(dllpath
,&ofs
,OF_EXIST
);
48 found
= TRUE
; // break out
55 CharLowerBuff(clsidstr
,strlen(clsidstr
));
56 if ((cr
= RegOpenKey(HKEY_CLASSES_ROOT
,COM_CLSID
,&hkEnum
)) == ERROR_SUCCESS
) {
59 while (cr
== ERROR_SUCCESS
&& !found
) {
60 cr
= RegEnumKey(hkEnum
,index
++,databuf
,512);
61 if (cr
== ERROR_SUCCESS
) {
62 CharLowerBuff(databuf
,strlen(databuf
));
63 if (!(strcmp(databuf
,clsidstr
))) {
64 if ((cr
= RegOpenKeyEx(hkEnum
,databuf
,0,KEY_READ
,&hksub
)) == ERROR_SUCCESS
) {
65 if ((cr
= RegOpenKeyEx(hksub
,INPROC_SERVER
,0,KEY_READ
,&hkpath
)) == ERROR_SUCCESS
) {
66 datatype
= REG_SZ
; datasize
= (DWORD
)dllpathsize
;
67 cr
= RegQueryValueEx(hkpath
,0,0,&datatype
,(LPBYTE
)dllpath
,&datasize
);
68 if (cr
== ERROR_SUCCESS
) {
69 memset(&ofs
,0,sizeof(OFSTRUCT
));
70 ofs
.cBytes
= sizeof(OFSTRUCT
);
71 hfile
= OpenFile(dllpath
,&ofs
,OF_EXIST
);
78 found
= TRUE
; // break out
89 static LPASIODRVSTRUCT
newDrvStruct (HKEY hkey
,char *keyname
,int drvID
,LPASIODRVSTRUCT lpdrv
)
93 char dllpath
[MAXPATHLEN
];
96 DWORD datatype
,datasize
;
100 if ((cr
= RegOpenKeyExA(hkey
,keyname
,0,KEY_READ
,&hksub
)) == ERROR_SUCCESS
) {
102 datatype
= REG_SZ
; datasize
= 256;
103 cr
= RegQueryValueExA(hksub
,COM_CLSID
,0,&datatype
,(LPBYTE
)databuf
,&datasize
);
104 if (cr
== ERROR_SUCCESS
) {
105 rc
= findDrvPath (databuf
,dllpath
,MAXPATHLEN
);
107 lpdrv
= new ASIODRVSTRUCT
[1];
109 memset(lpdrv
,0,sizeof(ASIODRVSTRUCT
));
110 lpdrv
->drvID
= drvID
;
111 MultiByteToWideChar(CP_ACP
,0,(LPCSTR
)databuf
,-1,(LPWSTR
)wData
,100);
112 if ((cr
= CLSIDFromString((LPOLESTR
)wData
,(LPCLSID
)&clsid
)) == S_OK
) {
113 memcpy(&lpdrv
->clsid
,&clsid
,sizeof(CLSID
));
116 datatype
= REG_SZ
; datasize
= 256;
117 cr
= RegQueryValueExA(hksub
,ASIODRV_DESC
,0,&datatype
,(LPBYTE
)databuf
,&datasize
);
118 if (cr
== ERROR_SUCCESS
) {
119 strcpy(lpdrv
->drvname
,databuf
);
121 else strcpy(lpdrv
->drvname
,keyname
);
128 else lpdrv
->next
= newDrvStruct(hkey
,keyname
,drvID
+1,lpdrv
->next
);
133 static void deleteDrvStruct (LPASIODRVSTRUCT lpdrv
)
138 deleteDrvStruct(lpdrv
->next
);
139 if (lpdrv
->asiodrv
) {
140 iasio
= (IASIO
*)lpdrv
->asiodrv
;
148 static LPASIODRVSTRUCT
getDrvStruct (int drvID
,LPASIODRVSTRUCT lpdrv
)
151 if (lpdrv
->drvID
== drvID
) return lpdrv
;
156 // ******************************************************************
159 // ******************************************************************
161 // ******************************************************************
162 AsioDriverList::AsioDriverList ()
165 char keyname
[MAXDRVNAMELEN
];
175 cr
= RegOpenKeyA(HKEY_LOCAL_MACHINE
,ASIO_PATH
,&hkEnum
);
177 cr
= RegOpenKey(HKEY_LOCAL_MACHINE
,ASIO_PATH
,&hkEnum
);
179 while (cr
== ERROR_SUCCESS
) {
181 if ((cr
= RegEnumKeyA(hkEnum
,index
++,keyname
,MAXDRVNAMELEN
))== ERROR_SUCCESS
) {
183 if ((cr
= RegEnumKey(hkEnum
,index
++,keyname
,MAXDRVNAMELEN
))== ERROR_SUCCESS
) {
185 lpdrvlist
= newDrvStruct (hkEnum
,keyname
,0,lpdrvlist
);
189 if (hkEnum
) RegCloseKey(hkEnum
);
197 if (numdrv
) CoInitialize(0); // initialize COM
200 AsioDriverList::~AsioDriverList ()
203 deleteDrvStruct(lpdrvlist
);
209 LONG
AsioDriverList::asioGetNumDev (VOID
)
215 LONG
AsioDriverList::asioOpenDriver (int drvID
,LPVOID
*asiodrv
)
217 LPASIODRVSTRUCT lpdrv
= 0;
220 if (!asiodrv
) return DRVERR_INVALID_PARAM
;
222 if ((lpdrv
= getDrvStruct(drvID
,lpdrvlist
)) != 0) {
223 if (!lpdrv
->asiodrv
) {
224 rc
= CoCreateInstance(lpdrv
->clsid
,0,CLSCTX_INPROC_SERVER
,lpdrv
->clsid
,asiodrv
);
226 lpdrv
->asiodrv
= *asiodrv
;
229 // else if (rc == REGDB_E_CLASSNOTREG)
230 // strcpy (info->messageText, "Driver not registered in the Registration Database!");
232 else rc
= DRVERR_DEVICE_ALREADY_OPEN
;
234 else rc
= DRVERR_DEVICE_NOT_FOUND
;
240 LONG
AsioDriverList::asioCloseDriver (int drvID
)
242 LPASIODRVSTRUCT lpdrv
= 0;
245 if ((lpdrv
= getDrvStruct(drvID
,lpdrvlist
)) != 0) {
246 if (lpdrv
->asiodrv
) {
247 iasio
= (IASIO
*)lpdrv
->asiodrv
;
256 LONG
AsioDriverList::asioGetDriverName (int drvID
,char *drvname
,int drvnamesize
)
258 LPASIODRVSTRUCT lpdrv
= 0;
260 if (!drvname
) return DRVERR_INVALID_PARAM
;
262 if ((lpdrv
= getDrvStruct(drvID
,lpdrvlist
)) != 0) {
263 if (strlen(lpdrv
->drvname
) < (unsigned int)drvnamesize
) {
264 strcpy(drvname
,lpdrv
->drvname
);
267 memcpy(drvname
,lpdrv
->drvname
,drvnamesize
-4);
268 drvname
[drvnamesize
-4] = '.';
269 drvname
[drvnamesize
-3] = '.';
270 drvname
[drvnamesize
-2] = '.';
271 drvname
[drvnamesize
-1] = 0;
275 return DRVERR_DEVICE_NOT_FOUND
;
278 LONG
AsioDriverList::asioGetDriverPath (int drvID
,char *dllpath
,int dllpathsize
)
280 LPASIODRVSTRUCT lpdrv
= 0;
282 if (!dllpath
) return DRVERR_INVALID_PARAM
;
284 if ((lpdrv
= getDrvStruct(drvID
,lpdrvlist
)) != 0) {
285 if (strlen(lpdrv
->dllpath
) < (unsigned int)dllpathsize
) {
286 strcpy(dllpath
,lpdrv
->dllpath
);
290 return DRVERR_INVALID_PARAM
;
292 return DRVERR_DEVICE_NOT_FOUND
;
295 LONG
AsioDriverList::asioGetDriverCLSID (int drvID
,CLSID
*clsid
)
297 LPASIODRVSTRUCT lpdrv
= 0;
299 if (!clsid
) return DRVERR_INVALID_PARAM
;
301 if ((lpdrv
= getDrvStruct(drvID
,lpdrvlist
)) != 0) {
302 memcpy(clsid
,&lpdrv
->clsid
,sizeof(CLSID
));
305 return DRVERR_DEVICE_NOT_FOUND
;