CreateFile() question?

Hi,All
the volume of my usb storage is “J”,I want to createfile() by the flow two
method,
but the result is out of my understanding.

m_strPath=“\\?\USB#Vid_0ed1&Pid_6620#5&76b405d&0&1#{a5dcbf10-6530-11d2-901f-00c04fb951ed}”;

HANDLE hCom = CreateFile(
m_strPath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,
0,
NULL);
HANDLE hDevice=CreateFile(“\\.\j:”,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
the hCom and hDevice are all VALID_HANDLE_VALUE.
by their value is not same,why?
thanks!

You open different symbolic links. Why would you think that the
returned handles should be the same ?
Norbert.

“Those who forget the past are doomed to repeat it.”
---- snip ----

Hi,All
the volume of my usb storage is “J”,I want to createfile() by the flow two
method,
but the result is out of my understanding.

m_strPath=“\\?\USB#Vid_0ed1&Pid_6620#5&76b405d&0&1#{a5dcbf10-6530-11d2-901f-00c04fb951ed}”;

HANDLE hCom = CreateFile(
m_strPath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,
0,
NULL);
HANDLE hDevice=CreateFile(“\\.\j:”,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
the hCom and hDevice are all VALID_HANDLE_VALUE.
by their value is not same,why?
thanks!


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stollmann.de
To unsubscribe send a blank email to xxxxx@lists.osr.com

---- snip ----

Assuming that you’re opening the same devices, CreateFile() will not return
same handle.
Even if you open same file you won’t have same handle.

Every new handle is like a new instance allowing you to do different I/O w/o
interference.

Regards,
Elias
“sunjinlong” wrote in message news:xxxxx@ntdev…
>
> Hi,All
> the volume of my usb storage is “J”,I want to createfile() by the flow two
> method,
> but the result is out of my understanding.
>
>
m_strPath=“\\?\USB#Vid_0ed1&Pid_6620#5&76b405d&0&1#{a5dcbf10-6530-11d2-90
1f-00c04fb951ed}”;
>
> HANDLE hCom = CreateFile(
> m_strPath,
> GENERIC_READ|GENERIC_WRITE,
> FILE_SHARE_READ|FILE_SHARE_WRITE,
> (LPSECURITY_ATTRIBUTES)NULL,
> OPEN_EXISTING,
> 0,
> NULL);
> HANDLE hDevice=CreateFile(“\\.\j:”,
> GENERIC_READ|GENERIC_WRITE,
> FILE_SHARE_READ|FILE_SHARE_WRITE,
> NULL,
> OPEN_EXISTING,
> 0,
> NULL);
> the hCom and hDevice are all VALID_HANDLE_VALUE.
> by their value is not same,why?
> thanks!
>
>

thanks!
but
then when i use
ReadFile(hDevice,buffer,512,&byteread,NULL)
the first method return error.
the second method retun ture.
Is it mean that the first method can’t be use?

“lallous” wrote in message news:xxxxx@ntdev…
>
> Assuming that you’re opening the same devices, CreateFile() will not
return
> same handle.
> Even if you open same file you won’t have same handle.
>
> Every new handle is like a new instance allowing you to do different I/O
w/o
> interference.
>
> Regards,
> Elias
> “sunjinlong” wrote in message news:xxxxx@ntdev…
> >
> > Hi,All
> > the volume of my usb storage is “J”,I want to createfile() by the flow
two
> > method,
> > but the result is out of my understanding.
> >
> >
>
m_strPath=“\\?\USB#Vid_0ed1&Pid_6620#5&76b405d&0&1#{a5dcbf10-6530-11d2-90
> 1f-00c04fb951ed}”;
> >
> > HANDLE hCom = CreateFile(
> > m_strPath,
> > GENERIC_READ|GENERIC_WRITE,
> > FILE_SHARE_READ|FILE_SHARE_WRITE,
> > (LPSECURITY_ATTRIBUTES)NULL,
> > OPEN_EXISTING,
> > 0,
> > NULL);
> > HANDLE hDevice=CreateFile(“\\.\j:”,
> > GENERIC_READ|GENERIC_WRITE,
> > FILE_SHARE_READ|FILE_SHARE_WRITE,
> > NULL,
> > OPEN_EXISTING,
> > 0,
> > NULL);
> > the hCom and hDevice are all VALID_HANDLE_VALUE.
> > by their value is not same,why?
> > thanks!
> >
> >
>
>
>
>