ReactOS  0.4.14-dev-854-gb9426a3
streamci.c File Reference
#include "precomp.h"
Include dependency graph for streamci.c:

Go to the source code of this file.

Functions

DWORD PerformIO (IN HANDLE hDevice, IN DWORD dwCtlCode, IN LPVOID lpBufferIn, IN DWORD dwBufferSizeIn, OUT LPVOID lpBufferOut, OUT DWORD dwBufferSizeOut, OUT LPDWORD lpNumberBytes)
 
DWORD InstallSoftwareDeviceInterface (IN LPGUID DeviceId, IN LPGUID InterfaceId, IN LPWSTR ReferenceString)
 
DWORD InstallSoftwareDeviceInterfaceInf (IN LPWSTR InfName, IN LPWSTR SectionName)
 
VOID WINAPI StreamingDeviceSetupW (IN HWND hwnd, IN HINSTANCE hinst, IN LPWSTR lpszCmdLine, IN int nCmdShow)
 

Function Documentation

◆ InstallSoftwareDeviceInterface()

DWORD InstallSoftwareDeviceInterface ( IN LPGUID  DeviceId,
IN LPGUID  InterfaceId,
IN LPWSTR  ReferenceString 
)

Definition at line 56 of file streamci.c.

59 {
60  HDEVINFO hDevInfo;
61  SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
63  PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData;
64  HANDLE hDevice;
65  PSWENUM_INSTALL_INTERFACE InstallInterface;
66  DWORD dwResult;
67 
69  if (!hDevInfo)
70  {
71  // failed
72  return GetLastError();
73  }
74 
75  DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
76  if (!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &SWBusGuid, 0, &DeviceInterfaceData))
77  {
78  // failed
80  return GetLastError();
81  }
82 
84  if (!DeviceInterfaceDetailData)
85  {
86  // failed
88  return GetLastError();
89  }
90 
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))
93  {
94  // failed
95  HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
97  return GetLastError();
98  }
99 
101  if (hDevice == INVALID_HANDLE_VALUE)
102  {
103  // failed
104  HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
106  return GetLastError();
107  }
108 
110  if (!InstallInterface)
111  {
112  // failed
113  CloseHandle(hDevice);
114  HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
116  return GetLastError();
117  }
118 
119  // init install interface param
120  InstallInterface->DeviceId = *DeviceId;
121  InstallInterface->InterfaceId = *InterfaceId;
122  wcscpy(InstallInterface->ReferenceString, ReferenceString);
123 
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);
126 
127  CloseHandle(hDevice);
128  HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
130  return dwResult;
131 }
#define CloseHandle
Definition: compat.h:406
#define IOCTL_SWENUM_INSTALL_INTERFACE
Definition: swenum.h:6
WCHAR DevicePath[ANYSIZE_ARRAY]
Definition: setupapi.h:850
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2297
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, DWORD DeviceInterfaceDetailDataSize, PDWORD RequiredSize, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:3016
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
#define GENERIC_WRITE
Definition: nt_native.h:90
_In_ CONST GUID _In_opt_ PUNICODE_STRING ReferenceString
Definition: iofuncs.h:1134
struct _SWENUM_INSTALL_INTERFACE * PSWENUM_INSTALL_INTERFACE
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:434
WCHAR ReferenceString[1]
Definition: swenum.h:18
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W * PSP_DEVICE_INTERFACE_DETAIL_DATA_W
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define GENERIC_READ
Definition: compat.h:124
#define STATIC_BUSID_SoftwareDeviceEnumerator
Definition: swenum.h:25
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
DWORD PerformIO(IN HANDLE hDevice, IN DWORD dwCtlCode, IN LPVOID lpBufferIn, IN DWORD dwBufferSizeIn, OUT LPVOID lpBufferOut, OUT DWORD dwBufferSizeOut, OUT LPDWORD lpNumberBytes)
Definition: streamci.c:13
#define CreateFileW
Definition: compat.h:408
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
struct _SP_DEVICE_INTERFACE_DATA SP_DEVICE_INTERFACE_DATA
struct _SWENUM_INSTALL_INTERFACE SWENUM_INSTALL_INTERFACE
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:402
#define DIGCF_PRESENT
Definition: setupapi.h:171

Referenced by StreamingDeviceSetupW().

◆ InstallSoftwareDeviceInterfaceInf()

DWORD InstallSoftwareDeviceInterfaceInf ( IN LPWSTR  InfName,
IN LPWSTR  SectionName 
)

Definition at line 134 of file streamci.c.

136 {
137  HDEVINFO hDevInfo;
138  HINF hInf;
139  HKEY hKey;
140  SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
142 
143  hDevInfo = SetupDiGetClassDevsW(&SWBusGuid, NULL, NULL, 0);
144  if (!hDevInfo)
145  {
146  // failed
147  return GetLastError();
148  }
149 
150  DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
151  if (!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &SWBusGuid, 0, &DeviceInterfaceData))
152  {
153  // failed
154  return GetLastError();
155  }
156 
157  hInf = SetupOpenInfFileW(InfName, NULL, INF_STYLE_WIN4, NULL);
158  if (hInf == INVALID_HANDLE_VALUE)
159  {
161  return GetLastError();
162  }
163 
164  //
165  // FIXME check if interface is already installed
166  //
167 
168  hKey = SetupDiCreateDeviceInterfaceRegKeyW(hDevInfo, &DeviceInterfaceData, 0, KEY_ALL_ACCESS, hInf, SectionName);
169 
170  SetupCloseInfFile(hInf);
172  if (hKey != INVALID_HANDLE_VALUE)
173  {
174  RegCloseKey(hKey);
175  }
176  return ERROR_SUCCESS;
177 }
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define ERROR_SUCCESS
Definition: deptool.c:10
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2297
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, DWORD Reserved, REGSAM samDesired, HINF InfHandle, PCWSTR InfSectionName)
Definition: devinst.c:2618
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define STATIC_BUSID_SoftwareDeviceEnumerator
Definition: swenum.h:25
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
struct _SP_DEVICE_INTERFACE_DATA SP_DEVICE_INTERFACE_DATA

Referenced by StreamingDeviceSetupW().

◆ PerformIO()

DWORD PerformIO ( IN HANDLE  hDevice,
IN DWORD  dwCtlCode,
IN LPVOID  lpBufferIn,
IN DWORD  dwBufferSizeIn,
OUT LPVOID  lpBufferOut,
OUT DWORD  dwBufferSizeOut,
OUT LPDWORD  lpNumberBytes 
)

Definition at line 13 of file streamci.c.

20 {
22  DWORD dwResult;
23 
24  ZeroMemory(&overlapped, sizeof(OVERLAPPED));
26  if (!overlapped.hEvent)
27  {
28  // failed to init event
29  return GetLastError();
30  }
31 
32  if (DeviceIoControl(hDevice, dwCtlCode, lpBufferIn, dwBufferSizeIn, lpBufferOut, dwBufferSizeOut, lpNumberBytes, &overlapped))
33  {
34  dwResult = ERROR_SUCCESS;
35  }
36  else if (GetLastError() == ERROR_IO_PENDING)
37  {
38  if (GetOverlappedResult(hDevice, &overlapped, lpNumberBytes, TRUE))
39  {
40  dwResult = ERROR_SUCCESS;
41  }
42  else
43  {
44  dwResult = GetLastError();
45  }
46  }
47  else
48  {
49  dwResult = GetLastError();
50  }
51  CloseHandle(overlapped.hEvent);
52  return dwResult;
53 }
#define CreateEvent
Definition: winbase.h:3582
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1642
#define ERROR_IO_PENDING
Definition: dderror.h:15
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:82
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136

Referenced by InstallSoftwareDeviceInterface().

◆ StreamingDeviceSetupW()

VOID WINAPI StreamingDeviceSetupW ( IN HWND  hwnd,
IN HINSTANCE  hinst,
IN LPWSTR  lpszCmdLine,
IN int  nCmdShow 
)

Definition at line 182 of file streamci.c.

186 {
187  DWORD Length, dwResult;
188  LPWSTR pCmdLine;
189  LPWSTR pStr;
190  GUID Guids[2];
191  WCHAR DevicePath[MAX_PATH];
192  HRESULT hResult;
193  DWORD Index;
194 
195  Length = (wcslen(lpszCmdLine) + 1) * sizeof(WCHAR);
196 
198  if (pCmdLine == NULL)
199  {
200  // no memory
201  return;
202  }
203 
204  hResult = StringCbCopyExW(pCmdLine, Length, lpszCmdLine, NULL, NULL, STRSAFE_NULL_ON_FAILURE);
205  if (hResult != S_OK)
206  {
207  // failed
208  HeapFree(GetProcessHeap(), 0, pCmdLine);
209  return;
210  }
211 
212  pStr = wcstok(pCmdLine, L",\t\"");
213  Index = 0;
214  do
215  {
216  if (pStr == NULL)
217  {
218  // invalid parameter
219  HeapFree(GetProcessHeap(), 0, pCmdLine);
220  return;
221  }
222 
223  hResult = IIDFromString(pStr, &Guids[Index]);
224  if (hResult != S_OK)
225  {
226  // invalid parameter
227  HeapFree(GetProcessHeap(), 0, pCmdLine);
228  return;
229  }
230 
231  Index++;
232  pStr = wcstok(NULL, L",\t\"");
233 
234 
235  }while(Index < 2);
236 
237 
238  dwResult = InstallSoftwareDeviceInterface(&Guids[0], &Guids[1], pStr);
239  if (dwResult == ERROR_SUCCESS)
240  {
241  pStr = wcstok(NULL, L",\t\"");
242  if (pStr != NULL)
243  {
244  wcscpy(DevicePath, pStr);
245  pStr = wcstok(NULL, L",\t\"");
246  if (pStr != NULL)
247  {
248  dwResult = InstallSoftwareDeviceInterfaceInf(DevicePath, pStr);
249  }
250  }
251  }
252 }
#define ERROR_SUCCESS
Definition: deptool.c:10
_Check_return_ _CRTIMP wchar_t *__cdecl wcstok(_Inout_opt_z_ wchar_t *_Str, _In_z_ const wchar_t *_Delim)
DWORD InstallSoftwareDeviceInterface(IN LPGUID DeviceId, IN LPGUID InterfaceId, IN LPWSTR ReferenceString)
Definition: streamci.c:56
STRSAFEAPI StringCbCopyExW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:210
DWORD InstallSoftwareDeviceInterfaceInf(IN LPWSTR InfName, IN LPWSTR SectionName)
Definition: streamci.c:134
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI IIDFromString(LPCOLESTR s, IID *iid)
Definition: compobj.c:2374
#define MAX_PATH
Definition: compat.h:26
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define S_OK
Definition: intsafe.h:59
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define STRSAFE_NULL_ON_FAILURE
Definition: ntstrsafe.h:34
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:402