|
Hello Friends
I am trying to connect to USB Printer. For that I used SetupDi calls but not able to get devicePath using Enuminterface.
So, I tried to pass devicePath manually to CreateFile'first parameter o create Handle.
After searching a lot, I found that the H/W id is being used for devicepath and it is here that i found from registery
LPCWSTR devicePath = L "\\\\?\\USB\\VID_04A9&PID_10A2&REV_0109#{4d36e979-e325-11ce-bfc1-08002be10318}"
In curly brackets represent ClassID for Printer device.[tried USB ClassId too]
But I am getting INVALID_HANDLE always.
So,please let me know the what is right devicepath that i can pass to create file to get its handle.
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
Take a look at this snippet, it may give you an idea.
This is "under construction" code , not plug and pray!
I use it with strDevice = "USB".
There is a SetupDi API for getting "friendly name", somewhere in my messy code.
DWORD dwFlag = DIGCF_ALLCLASSES | DIGCF_PRESENT;
TRACE("\nSetupDiGetClassDevs %s ", strDevice);
HDEVINFO hDevInfo = SetupDiGetClassDevs(NULL,strDevice, NULL,dwFlag);
if( INVALID_HANDLE_VALUE == hDevInfo ) {
TRACE("\nINVALID_HANDLE_VALUE == hDevInfo ");
return false;
}
TRACE("\nFind all selected devices %s",strDevice);
SP_DEVINFO_DATA* pspDevInfoData =
(SP_DEVINFO_DATA*)HeapAlloc(GetProcessHeap(), 0, sizeof(SP_DEVINFO_DATA));
pspDevInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
int i = 0;
DWORD DataT ;
DWORD nSize=0 ;
TCHAR buf[MAX_PATH];
while (SetupDiEnumDeviceInfo(hDevInfo,i,pspDevInfoData))
{
SetupDiGetDeviceInstanceId(hDevInfo, pspDevInfoData, buf, sizeof(buf), &nSize);
{
TRACE("\nFind LittelWire ");
CString strTest = buf;
// CString strResult = strTest.SpanIncluding("0C9F");
int iFoundIndex = strTest.Find(strDeviceID);
TRACE("\nCount %i Buffer %s",i, buf);
if(iFoundIndex > 0 )
{
TRACE("\nCount %i Buffer %s Device %s found", i, buf, strDeviceID);
return true;
}
}
i++;
}
TRACE("\nDevice %s not found", strDeviceID);
return false;
|
|
|
|