Your code seems to be confused and lacking initialization.
This one, fast & dirty fixing, work compiled as plain C:
#include <windows.h>
#include <SetupAPI.h>
#include <stdio.h>
#include <stddef.h>
GUID GUID_DEVINTERFACE_USB_DEVICE = {0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}};
HANDLE webcam = NULL;
void UseDeviceIoControl(HANDLE hwebcam)
{
DWORD sizeOfgCP = 0;
OVERLAPPED oLap = {0};
if (DeviceIoControl(hwebcam, IOCTL_CHANGER_GET_STATUS, NULL, 0, NULL, 0, &sizeOfgCP, &oLap) != 0)
{
printf("Getting CHANGER_GET_STATUS worked %d\n", sizeOfgCP);
}
else
{
printf("Getting CHANGER_GET_STATUS failed. error %d\nRequired Size %d\n", GetLastError(), sizeOfgCP);
}
DCB webcamDCB;
if (GetCommState(webcam, &webcamDCB) != 0)
{
printf("Getting GetCommState worked! baud rate is %d\n", webcamDCB.BaudRate);
}
else
{
printf("Getting GetCommState failed %d\n", GetLastError());
}
}
int main(void)
{
HDEVINFO webdevices;
if ((webdevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE))) != NULL)
{
printf("SetupDiGetClassDevs Worked!!\n");
}
else
{
printf("SetupDiGetClassDevs didn't work error %d\n", GetLastError());
}
SP_DEVINFO_DATA webDevInfoDat;
webDevInfoDat.cbSize = sizeof(SP_DEVINFO_DATA);
SP_DEVICE_INTERFACE_DATA webInterDat;
webInterDat.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
int i=0;
SetupDiEnumDeviceInfo(webdevices, i, &webDevInfoDat);
BOOL sdei;
while (TRUE == (sdei = SetupDiEnumDeviceInterfaces(webdevices, NULL, &GUID_DEVINTERFACE_USB_DEVICE, i, &webInterDat)))
{
printf ("Device%d) ", i);
PSP_DEVICE_INTERFACE_DETAIL_DATA_A pwebInterDetDat = NULL;
DWORD interDetSiz = 0;
DWORD reqInterDetSiz = 0;
DWORD err = SetupDiGetDeviceInterfaceDetail(webdevices, &webInterDat, pwebInterDetDat, interDetSiz, &reqInterDetSiz, &webDevInfoDat);
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
{
printf("SetupDiGetDeviceInterfaceDetail failed!\n");
ExitProcess(1);
}
pwebInterDetDat = malloc(reqInterDetSiz);
pwebInterDetDat->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
interDetSiz = reqInterDetSiz;
if (SetupDiGetDeviceInterfaceDetail(webdevices, &webInterDat, pwebInterDetDat, interDetSiz, &reqInterDetSiz, &webDevInfoDat))
{
printf("Interface Detail Data\nDevicePath: %s\nRequired Size: %d\n", pwebInterDetDat->DevicePath, reqInterDetSiz);
}
else
{
printf("Getting SetupDiGetDeviceDetail error %d RequiredSize %d\n", GetLastError(), reqInterDetSiz);
}
webcam = CreateFile(pwebInterDetDat->DevicePath, (GENERIC_READ | GENERIC_WRITE), 0, NULL, OPEN_EXISTING, 0, NULL);
if (webcam == INVALID_HANDLE_VALUE)
{
printf("Creating File didn't work %d\n", GetLastError());
}
else
{
printf("Creating File did work\n");
if (pwebInterDetDat->DevicePath[13] != '9')
{ CloseHandle(webcam);
}
else
{
printf("save this file\n");
UseDeviceIoControl(webcam);
break;
}
}
printf("\n");
i++;
webInterDat.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
free(pwebInterDetDat);
}
}
Note the dynamic allocation of buffers as required by system.
Of course the code lacks of extended error checks.