I cannot do a printf since I am in a DLL, but I used the MessageBoxW to confirm that the \?\ is indeed present.
The CreateFile returns a -1 and the GetLastError returns a 2.
I have hard coded these strings and tied to open the device with no luck.
I see the I2C devices in Device Manager with a loaded driver (iaioi2c.sys). The I2Cpublic.h include file from Intel has this:
DEFINE_GUID(I2C_LPSS_INTERFACE_GUID,
0x4fd00181, 0xf807, 0x41aa, 0x8d, 0x33, 0xf2, 0x2c, 0x5d, 0x7c, 0xae, 0xbd);
I am including the entire function here so all is visible. Thanks for the help Tim.
DECLDIR int InitializeSession()
{
HDEVINFO DeviceInfoSet;
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData = NULL;
ULONG requiredSize = 0, Length;
DWORD Index = 0;
HANDLE tempHandle;
WCHAR *i2cDevice = I2C_CONTROLLER_NUM; // L"0f41"
DWORD LastError;
DWORD status = SUCCESS;
DeviceInfoSet = SetupDiGetClassDevs((GUID*)&I2C_LPSS_INTERFACE_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return status = INVALID_HANDLE;
SetupDiEnumDeviceInfo(DeviceInfoSet, Index, &DeviceInfoData);
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
while (SetupDiEnumDeviceInfo(DeviceInfoSet, Index, &DeviceInfoData))
{
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
SetupDiCreateDeviceInterface(DeviceInfoSet, &DeviceInfoData, &DeviceInfoData.ClassGuid, NULL, 0, &DeviceInterfaceData);
// call the first time to get required buffer size
status = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, NULL, 0, &requiredSize, NULL);
LastError = GetLastError();
if (status == FALSE && LastError != ERROR_INSUFFICIENT_BUFFER)
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return LastError;
}
// allocate required buffer
if (requiredSize)
DeviceInterfaceDetailData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)LocalAlloc(LMEM_FIXED, requiredSize);
if (DeviceInterfaceDetailData == NULL)
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return status = INSUFFICIENT_MEMORY;
}
// call the second time to get detailed info
DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
Length = requiredSize;
status = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, DeviceInterfaceDetailData, Length, &requiredSize, NULL);
if (status == FALSE)
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
LocalFree(DeviceInterfaceDetailData);
return GetLastError();
}
// check for i2c controller #1 and break
if (wcsstr(DeviceInterfaceDetailData->DevicePath, i2cDevice) != NULL)
break;
Index++;
}
if (DeviceInterfaceDetailData)
{
tempHandle = CreateFileW(DeviceInterfaceDetailData->DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
LastError = GetLastError();
if (tempHandle == INVALID_HANDLE_VALUE)
status = INVALID_HANDLE;
else
lvdsControllerHandle = tempHandle;
}
LocalFree(DeviceInterfaceDetailData);
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return status;
}