From: Doron Holan [MSFT] on
are you sure your driver is processing IRP_MJ_CREATE and completing it with
status_success?

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


<flashlib(a)gmail.com> wrote in message
news:a98bf621-159a-4879-a2f2-eb254938155a(a)a5g2000prg.googlegroups.com...
On 4��11��, ����2ʱ23��, "Doron Holan [MSFT]" <dor...(a)online.microsoft.com>
wrote:
> what fails? the CreateFile call? which device interface guid are you
> trying to open?
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> <flash...(a)gmail.com> wrote in message
>
> news:0ed7c14a-66e5-46b2-a6b3-b20a706852ad(a)w8g2000prd.googlegroups.com...
> On 4��10��, ����12ʱ59��, "Doron Holan [MSFT]"
> <dor...(a)online.microsoft.com>
> wrote:
>
>
>
> > why are you getting a path to the hub? just enumerate the instances of
> > your
> > device's device interface guid
>
> > d
>
> > --
> > Please do not send e-mail directly to this alias. this alias is for
> > newsgroup purposes only.
> > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
>
> > <flash...(a)gmail.com> wrote in message
>
> >news:78daad28-f9a9-4c80-b215-0133441639db(a)w8g2000prd.googlegroups.com...
>
> > > Dear all,
>
> > > I'm tring to communicate with a USB device. I first enum the USB hub
> > > and get the path of my device. Then I use CreateFile with the path to
> > > open the device, but it always return an invalid handls. I use
> > > GetLastError and get ERROR_FILE_NOT_FOUND.
> > > There is another program which can communicate with the device
> > > successfully. Can any body tell me why my CreateFile failed?
> > > I know there is a program IRPTrace which can trace the IRP to the
> > > device driver. I ran it and found the first IRP issued by both mine
> > > and the program which can successfully open the device is
> > > IRP_MJ_CREATE.
> > > There are some different in the IRPTrace log for the program, but I
> > > don't what those mean. Can any body help me?
>
> > > Thanks and BR.
> > > Jacky
>
> Hi Doron,
>
> I'm now using the way you show me, get the path by the GUID, but I
> still can't createfile, why?

Yes, it failed with the CreateFile call. I'm using the following GUID
to open the file:
DEFINE_GUID(USBGuid, 0xa5dcbf10,0x6530,0x11d2,0x90,0x1f,0x00,0xc0,0x4f,
0xb9,0x51,0xed);

From: flashlib on
On 4ÔÂ11ÈÕ, ÏÂÎç2ʱ04·Ö, "Doron Holan [MSFT]" <dor....(a)online.microsoft.com>
wrote:
> are you sure your driver is processing IRP_MJ_CREATE and completing it with
> status_success?
>
> d
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no rights..
>
> <flash...(a)gmail.com> wrote in message
>
> news:a98bf621-159a-4879-a2f2-eb254938155a(a)a5g2000prg.googlegroups.com...
> On 4ÔÂ11ÈÕ, ÉÏÎç2ʱ23·Ö, "Doron Holan [MSFT]" <dor....(a)online.microsoft.com>
> wrote:
>
>
>
> > what fails? the CreateFile call? which device interface guid are you
> > trying to open?
>
> > --
> > Please do not send e-mail directly to this alias. this alias is for
> > newsgroup purposes only.
> > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
>
> > <flash...(a)gmail.com> wrote in message
>
> >news:0ed7c14a-66e5-46b2-a6b3-b20a706852ad(a)w8g2000prd.googlegroups.com...
> > On 4ÔÂ10ÈÕ, ÏÂÎç12ʱ59·Ö, "Doron Holan [MSFT]"
> > <dor...(a)online.microsoft.com>
> > wrote:
>
> > > why are you getting a path to the hub? just enumerate the instances of
> > > your
> > > device's device interface guid
>
> > > d
>
> > > --
> > > Please do not send e-mail directly to this alias. this alias is for
> > > newsgroup purposes only.
> > > This posting is provided "AS IS" with no warranties, and confers no
> > > rights.
>
> > > <flash...(a)gmail.com> wrote in message
>
> > >news:78daad28-f9a9-4c80-b215-0133441639db(a)w8g2000prd.googlegroups.com....
>
> > > > Dear all,
>
> > > > I'm tring to communicate with a USB device. I first enum the USB hub
> > > > and get the path of my device. Then I use CreateFile with the path to
> > > > open the device, but it always return an invalid handls. I use
> > > > GetLastError and get ERROR_FILE_NOT_FOUND.
> > > > There is another program which can communicate with the device
> > > > successfully. Can any body tell me why my CreateFile failed?
> > > > I know there is a program IRPTrace which can trace the IRP to the
> > > > device driver. I ran it and found the first IRP issued by both mine
> > > > and the program which can successfully open the device is
> > > > IRP_MJ_CREATE.
> > > > There are some different in the IRPTrace log for the program, but I
> > > > don't what those mean. Can any body help me?
>
> > > > Thanks and BR.
> > > > Jacky
>
> > Hi Doron,
>
> > I'm now using the way you show me, get the path by the GUID, but I
> > still can't createfile, why?
>
> Yes, it failed with the CreateFile call. I'm using the following GUID
> to open the file:
> DEFINE_GUID(USBGuid, 0xa5dcbf10,0x6530,0x11d2,0x90,0x1f,0x00,0xc0,0x4f,
> 0xb9,0x51,0xed);

Yes, I'm sure. Another program send IRP_MJ_CREATE to the driver and
returned success. I see this through IRPTrace.
From: Tim Roberts on
flashlib(a)gmail.com wrote:
>>
>> Yes, it failed with the CreateFile call. I'm using the following GUID
>> to open the file:
>> DEFINE_GUID(USBGuid, 0xa5dcbf10,0x6530,0x11d2,0x90,0x1f,0x00,0xc0,0x4f,
>> 0xb9,0x51,0xed);
>
>Yes, I'm sure. Another program send IRP_MJ_CREATE to the driver and
>returned success. I see this through IRPTrace.

You would save ALL of us an enormous amount of time by just posting the
code you are using to get the file name and open the driver, instead of
forcing us to guess how you actually did it.
--
Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: flashlib on
Alghouh I don't if there is any problem in my code( It succeed when I
install EZUSB driver to my device, but failed with the custom driver
which is written by other people), I post it here for a deep discuss:
//////////////////////////////////
start////////////////////////////////////
#define INTERFACE_DETAIL_SIZE (1024)
#define MAX_DEVICE (128)
#define MAX_PATH_LEN (256)

DEFINE_GUID(CameraClassGuid, 0xa5dcbf10,0x6530,0x11d2,0x90,0x1f,
0x00,0xc0,0x4f,0xb9,0x51,0xed);// $BDLMQ(Busb device

// Get device path according to GUID
// lpGuid: pointer to GUID
// pszDevicePath: pointer to device path pointer
// return: Device number
int CRegisterControlDlg::GetDevicePath(LPGUID lpGuid, LPTSTR*
pszDevicePath)
{
HDEVINFO hDevInfoSet;
SP_DEVICE_INTERFACE_DATA ifdata;
PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
int nCount;
BOOL bResult;

// get a handle to the GUID class device
hDevInfoSet = ::SetupDiGetClassDevs(lpGuid, // class GUID
NULL, //
NULL, //
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); //

if(hDevInfoSet == INVALID_HANDLE_VALUE)
{
return 0;
}

// alloc mem
pDetail =
(PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT,
INTERFACE_DETAIL_SIZE);

pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

nCount = 0;
bResult = TRUE;

// test device
while (bResult)
{
ifdata.cbSize=sizeof(ifdata);

// find device with the GUID
bResult = ::SetupDiEnumDeviceInterfaces(
hDevInfoSet,
NULL,
lpGuid,
(ULONG)nCount,
&ifdata);

if(bResult)
{
// get the detail of device
bResult = SetupDiGetInterfaceDeviceDetail(
hDevInfoSet,
&ifdata,
pDetail,
INTERFACE_DETAIL_SIZE,
NULL,
NULL);

if(bResult)
{
// get device path
int iPathLen = _tcslen(pDetail->DevicePath)*sizeof(TCHAR) + 1;
_tcsncpy_s(pszDevicePath[nCount], iPathLen, pDetail->DevicePath,
MAX_PATH_LEN);

// record
nCount++;
}
}
}

// release mem
::GlobalFree(pDetail);

// close handle
::SetupDiDestroyDeviceInfoList(hDevInfoSet);

return nCount;
}


void CRegisterControlDlg::OpenUSBDevice()
{
int i;
TCHAR* szDevicePath[MAX_DEVICE]; // device path

// path holder
for(i=0; i<MAX_DEVICE; i++) szDevicePath[i] = new
TCHAR[ MAX_PATH_LEN ];

// get device path
int nDevice = GetDevicePath((LPGUID)&CameraClassGuid, szDevicePath);
CString sOutput;
sOutput.Format( _T( "Find %d decive(s):" ), nDevice );
((CListBox *)GetDlgItem( IDC_OUTPUT ))->InsertString(-1, sOutput);

// get device info one by one
for(i=0; i<nDevice; i++)
{
((CListBox *)GetDlgItem( IDC_OUTPUT ))->InsertString(-1,
szDevicePath[i]);

// get pid/vid
CString sPath = szDevicePath[i];
sPath.MakeUpper();

int iPos = sPath.Find( _T( "_" ) );
sPath = sPath.Mid( iPos + 1 );
iPos = sPath.Find( _T( "&" ) );
CString sVID = sPath.Left( iPos );

iPos = sPath.Find( _T( "_" ) );
sPath = sPath.Mid( iPos + 1 );
iPos = sPath.Find( _T( "#" ) );
CString sPID = sPath.Left( iPos );

int Error_Code;
// check pid/vid
if ( sVID == DEVICE_VID && sPID == DEVICE_PID )
{
hDeviceHandle=CreateFile(
szDevicePath[i],
GENERIC_READ | GENERIC_WRITE,
0,//FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_ATTRIBUTE_NORMAL,
NULL
);
///////////////////////////////////////////////
// it failed here, always return ERROR_FILE_NOT_FOUND
///////////////////////////////////////////////
Error_Code = GetLastError();

if( hDeviceHandle != INVALID_HANDLE_VALUE )
{
((CListBox *)GetDlgItem( IDC_OUTPUT ))->InsertString(-1,
_T( "Device opened!" ) );
}
else
{
((CListBox *)GetDlgItem( IDC_OUTPUT ))->InsertString(-1,
_T( "Can't open device!" ) );
}

break;
}
}

// release memory
for(i=0;i<MAX_DEVICE;i++) delete []szDevicePath[i];
}
//////////////////////////////////
end////////////////////////////////////
From: flashlib on
In fact, this code works for many device. And for this device I want
to open, it works with the EZUSB driver but failed with the custom
drier. Is it possible that there is a authorization in the driver when
proccess the IRP_MJ_CREAT?