2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Configuration of network devices
4 * FILE: dll/win32/streamci/streamci.c
5 * PURPOSE: Streaming device class installer
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
13 PerformIO(IN HANDLE hDevice
,
16 IN DWORD dwBufferSizeIn
,
17 OUT LPVOID lpBufferOut
,
18 OUT DWORD dwBufferSizeOut
,
19 OUT LPDWORD lpNumberBytes
)
21 OVERLAPPED overlapped
;
24 ZeroMemory(&overlapped
, sizeof(OVERLAPPED
));
25 overlapped
.hEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
26 if (!overlapped
.hEvent
)
28 // failed to init event
29 return GetLastError();
32 if (DeviceIoControl(hDevice
, dwCtlCode
, lpBufferIn
, dwBufferSizeIn
, lpBufferOut
, dwBufferSizeOut
, lpNumberBytes
, &overlapped
))
34 dwResult
= ERROR_SUCCESS
;
36 else if (GetLastError() == ERROR_IO_PENDING
)
38 if (GetOverlappedResult(hDevice
, &overlapped
, lpNumberBytes
, TRUE
))
40 dwResult
= ERROR_SUCCESS
;
44 dwResult
= GetLastError();
49 dwResult
= GetLastError();
51 CloseHandle(overlapped
.hEvent
);
56 InstallSoftwareDeviceInterface(IN LPGUID DeviceId
,
57 IN LPGUID InterfaceId
,
58 IN LPWSTR ReferenceString
)
61 SP_DEVICE_INTERFACE_DATA DeviceInterfaceData
;
62 GUID SWBusGuid
= {STATIC_BUSID_SoftwareDeviceEnumerator
};
63 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
;
65 PSWENUM_INSTALL_INTERFACE InstallInterface
;
68 hDevInfo
= SetupDiGetClassDevsW(&SWBusGuid
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
| DIGCF_PRESENT
);
72 return GetLastError();
75 DeviceInterfaceData
.cbSize
= sizeof(SP_DEVICE_INTERFACE_DATA
);
76 if (!SetupDiEnumDeviceInterfaces(hDevInfo
, NULL
, &SWBusGuid
, 0, &DeviceInterfaceData
))
79 SetupDiDestroyDeviceInfoList(hDevInfo
);
80 return GetLastError();
83 DeviceInterfaceDetailData
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
) + sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
));
84 if (!DeviceInterfaceDetailData
)
87 SetupDiDestroyDeviceInfoList(hDevInfo
);
88 return GetLastError();
91 DeviceInterfaceDetailData
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
92 if (!SetupDiGetDeviceInterfaceDetailW(hDevInfo
, &DeviceInterfaceData
, DeviceInterfaceDetailData
,MAX_PATH
* sizeof(WCHAR
) + sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
), NULL
, NULL
))
95 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData
);
96 SetupDiDestroyDeviceInfoList(hDevInfo
);
97 return GetLastError();
100 hDevice
= CreateFileW(DeviceInterfaceDetailData
->DevicePath
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_OVERLAPPED
|FILE_ATTRIBUTE_NORMAL
, NULL
);
101 if (hDevice
== INVALID_HANDLE_VALUE
)
104 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData
);
105 SetupDiDestroyDeviceInfoList(hDevInfo
);
106 return GetLastError();
109 InstallInterface
= (PSWENUM_INSTALL_INTERFACE
)HeapAlloc(GetProcessHeap(), 0, sizeof(SWENUM_INSTALL_INTERFACE
) + wcslen(ReferenceString
) * sizeof(WCHAR
));
110 if (!InstallInterface
)
113 CloseHandle(hDevice
);
114 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData
);
115 SetupDiDestroyDeviceInfoList(hDevInfo
);
116 return GetLastError();
119 // init install interface param
120 InstallInterface
->DeviceId
= *DeviceId
;
121 InstallInterface
->InterfaceId
= *InterfaceId
;
122 wcscpy(InstallInterface
->ReferenceString
, ReferenceString
);
124 PerformIO(hDevice
, IOCTL_SWENUM_INSTALL_INTERFACE
, InstallInterface
, sizeof(SWENUM_INSTALL_INTERFACE
) + wcslen(ReferenceString
) * sizeof(WCHAR
), NULL
, 0, NULL
);
125 dwResult
= HeapFree(GetProcessHeap(), 0, InstallInterface
);
127 CloseHandle(hDevice
);
128 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData
);
129 SetupDiDestroyDeviceInfoList(hDevInfo
);
134 InstallSoftwareDeviceInterfaceInf(IN LPWSTR InfName
,
135 IN LPWSTR SectionName
)
140 SP_DEVICE_INTERFACE_DATA DeviceInterfaceData
;
141 GUID SWBusGuid
= {STATIC_BUSID_SoftwareDeviceEnumerator
};
143 hDevInfo
= SetupDiGetClassDevsW(&SWBusGuid
, NULL
, NULL
, 0);
147 return GetLastError();
150 DeviceInterfaceData
.cbSize
= sizeof(SP_DEVICE_INTERFACE_DATA
);
151 if (!SetupDiEnumDeviceInterfaces(hDevInfo
, NULL
, &SWBusGuid
, 0, &DeviceInterfaceData
))
154 return GetLastError();
157 hInf
= SetupOpenInfFileW(InfName
, NULL
, INF_STYLE_WIN4
, NULL
);
158 if (hInf
== INVALID_HANDLE_VALUE
)
160 SetupDiDestroyDeviceInfoList(hDevInfo
);
161 return GetLastError();
165 // FIXME check if interface is already installed
168 hKey
= SetupDiCreateDeviceInterfaceRegKeyW(hDevInfo
, &DeviceInterfaceData
, 0, KEY_ALL_ACCESS
, hInf
, SectionName
);
170 SetupCloseInfFile(hInf
);
171 SetupDiDestroyDeviceInfoList(hDevInfo
);
172 if (hKey
!= INVALID_HANDLE_VALUE
)
176 return ERROR_SUCCESS
;
182 StreamingDeviceSetupW(IN HWND hwnd
,
184 IN LPWSTR lpszCmdLine
,
187 DWORD Length
, dwResult
;
191 WCHAR DevicePath
[MAX_PATH
];
195 Length
= (wcslen(lpszCmdLine
) + 1) * sizeof(WCHAR
);
197 pCmdLine
= (LPWSTR
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, Length
);
198 if (pCmdLine
== NULL
)
204 hResult
= StringCbCopyExW(pCmdLine
, Length
, lpszCmdLine
, NULL
, NULL
, STRSAFE_NULL_ON_FAILURE
);
208 HeapFree(GetProcessHeap(), 0, pCmdLine
);
212 pStr
= wcstok(pCmdLine
, L
",\t\"");
219 HeapFree(GetProcessHeap(), 0, pCmdLine
);
223 hResult
= IIDFromString(pStr
, &Guids
[Index
]);
227 HeapFree(GetProcessHeap(), 0, pCmdLine
);
232 pStr
= wcstok(NULL
, L
",\t\"");
238 dwResult
= InstallSoftwareDeviceInterface(&Guids
[0], &Guids
[1], pStr
);
239 if (dwResult
== ERROR_SUCCESS
)
241 pStr
= wcstok(NULL
, L
",\t\"");
244 wcscpy(DevicePath
, pStr
);
245 pStr
= wcstok(NULL
, L
",\t\"");
248 dwResult
= InstallSoftwareDeviceInterfaceInf(DevicePath
, pStr
);