Hello everyone!!
I want to find out all the devices attach to the system. So i am using “QueryDosDevice()” API to get all the devices name. “QueryDosDevice()” is working correctly on almost all systems. But one of the system with configuration
OS:windows server 2003 with x64bit processor “QueryDosDevice()” API has started failing.
GetLastError is returning the error code: 234 which is “ERROR_MORE_DATA”.
Whether any one is having any idea what could be wrong here??
any help will be greatly appriciated.
thanks in advance.
Not sure if this is your problem, but look at KB 931305 “Error message when
you run a program that uses the QueryDosDeviceA function: “ERROR_MORE_DATA””
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Thursday, November 20, 2008 5:19 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] QueryDosDevice() failed
Hello everyone!!
I want to find out all the devices attach to the system. So i am using
“QueryDosDevice()” API to get all the devices name. “QueryDosDevice()” is
working correctly on almost all systems. But one of the system with
configuration
OS:windows server 2003 with x64bit processor “QueryDosDevice()” API has
started failing.
GetLastError is returning the error code: 234 which is “ERROR_MORE_DATA”.
Whether any one is having any idea what could be wrong here??
any help will be greatly appriciated.
thanks in advance.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
This means that you need to use a larger buffer to contain all of the name strings, IIRC.
BTW, QDD only returns symbolic links in the \DosDevices object manager directory. There is no such requirement that all devices create such a symlink for Win32 apps. In fact, most PnP devices won’t.
Also, not everything with a symlink in \DosDevices is a device, per-se. What are you really trying to accomplish here?
A better way to get stock of hardware installed on the system is to use the SetupDi setupapi routines, as demonstrated by the devcon sample.
- S
-----Original Message-----
From: xxxxx@hotmail.com
Sent: Thursday, November 20, 2008 04:17
To: Windows System Software Devs Interest List
Subject: [ntdev] QueryDosDevice() failed
Hello everyone!!
I want to find out all the devices attach to the system. So i am using “QueryDosDevice()” API to get all the devices name. “QueryDosDevice()” is working correctly on almost all systems. But one of the system with configuration
OS:windows server 2003 with x64bit processor “QueryDosDevice()” API has started failing.
GetLastError is returning the error code: 234 which is “ERROR_MORE_DATA”.
Whether any one is having any idea what could be wrong here??
any help will be greatly appriciated.
thanks in advance.
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
Hi Ken Cross and Ken Johnson
thanks for your reply.
As you say that i need to use more larger buffer.
Initialy my buffer size is 8192bytes and actually my QueryDosDevice is in a while loop in which i am cheking the return value of QueryDosDevice and if it is “ERROR_INSUFFICIENT_BUFFER” then i am multiping the previous buffer size by two and again perform QueryDosDevice.
This mechanism working fine on almost all systems but one of the system is continuosly returning “ERROR_MORE_DATA” even after the loop of 15 to 20 times.
MSDN is also specifing that if the buffer is too small, the function fails and the last error code is “ERROR_INSUFFICIENT_BUFFER”. No where given that error “ERROR_MORE_DATA” will get in such situation.
>What are you really trying to accomplish here?
so here i am identifing all the Tape devices attached to the system. And as the tape device can work with enable/disable Tape class driver. So i need to find out all the Tape device object if it is enable and all adapter objects(like scsi adapter) if Tape class drive is disable. So for that pursose i am using QueryDosDevice.
Could you post the offending code?
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Thursday, November 20, 2008 11:52 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] QueryDosDevice() failed
Hi Ken Cross and Ken Johnson
thanks for your reply.
As you say that i need to use more larger buffer.
Initialy my buffer size is 8192bytes and actually my QueryDosDevice is in a
while loop in which i am cheking the return value of QueryDosDevice and if
it is “ERROR_INSUFFICIENT_BUFFER” then i am multiping the previous buffer
size by two and again perform QueryDosDevice.
This mechanism working fine on almost all systems but one of the system is
continuosly returning “ERROR_MORE_DATA” even after the loop of 15 to 20
times.
MSDN is also specifing that if the buffer is too small, the function fails
and the last error code is “ERROR_INSUFFICIENT_BUFFER”. No where given that
error “ERROR_MORE_DATA” will get in such situation.
>What are you really trying to accomplish here?
so here i am identifing all the Tape devices attached to the system. And as
the tape device can work with enable/disable Tape class driver. So i need to
find out all the Tape device object if it is enable and all adapter
objects(like scsi adapter) if Tape class drive is disable. So for that
pursose i am using QueryDosDevice.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
hi ken thanks for your reply
here is my code:-
#define MAX_BUF_QDD 8192
uint uiRepeatCnt = 1;
char *pszDosDeviceName = NULL;
pszDosDeviceName = (char*)malloc(MAX_BUF_QDD);
do
{
if(pszDosDeviceName == NULL)
{
FormatSystemError(IDS_SYSC_MALLOC, -1, FILE, GetLastError(), MSGID_MALLOC, szLogMsg);
PrintLog(LEVEL0, SYSERR, szLogMsg);
return FALSE;
}
memset(pszDosDeviceName, 0, MAX_BUF_QDD * uiRepeatCnt);
dwRet = QueryDosDevice(NULL, pszDosDeviceName, (MAX_BUF_QDD * uiRepeatCnt));
if(dwRet == 0)
{
if(ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
uiRepeatCnt++;
pszDosDeviceName = (char*)realloc(pszDosDeviceName,MAX_BUF_QDD * uiRepeatCnt);
continue;
}
break;
}
}while(dwRet == 0);
I didn’t see the original post, but I see many problems with this code…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Sunday, November 23, 2008 11:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] QueryDosDevice() failed
hi ken thanks for your reply
here is my code:-
#define MAX_BUF_QDD 8192
uint uiRepeatCnt = 1;
char *pszDosDeviceName = NULL;
****
You are using an obsolete data type, ‘char’, to represent text. The data
type for the QueryDosDevice call is CLEARLY specified as LPTSTR, and it
makes little sense to use char, which is inconsistent with the specification
of the API. User-level code should always be written as Unicode-aware.
This is 2008.
LPTSTR pszDosDeviceName = NULL;
****
pszDosDeviceName = (char*)malloc(MAX_BUF_QDD);
****
pszDosDeviceName = (LPTSTR)malloc(MAX_BUF_QDD * sizeof(TCHAR);
****
do
{
if(pszDosDeviceName == NULL)
{
FormatSystemError(IDS_SYSC_MALLOC, -1, FILE,
GetLastError(), MSGID_MALLOC, szLogMsg);
PrintLog(LEVEL0, SYSERR, szLogMsg);
return FALSE;
}
memset(pszDosDeviceName, 0, MAX_BUF_QDD * uiRepeatCnt);
****
ZeroMemory(pszDosDeviceName, MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
It is not at all clear why this buffer needs to be zeroed at all. Why
bother?
****
dwRet = QueryDosDevice(NULL, pszDosDeviceName, (MAX_BUF_QDD
* uiRepeatCnt));
****
This is actually incorrect code, because it is passing a char* pointer to a
parameter which is clearly specified as LPTSTR
****
if(dwRet == 0)
{
if(ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
uiRepeatCnt++;
****
Note also that the typical technique is to double the buffer size each time,
rather than incrementing by a simple integer multiple.
****
pszDosDeviceName =
(char*)realloc(pszDosDeviceName,MAX_BUF_QDD * uiRepeatCnt);
****
pszDosDeviceName = (LPTSTR)realloc(pszDosDeviceName,
MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
****
continue;
}
break;
****
Why not just free the buffer and return FALSE?
****
}
}while(dwRet == 0);
***
This is an odd construct for a loop. Why not just while(TRUE) and break as
appropriate. A do-while loop is hard to reason about.
I used code similar to this and created a program that actually works, and
returns a valid set of information. I expect that it will be available for
download from my Web site within a day or two. It generates a correct list
of all devices. Send me private email to get the complete source if you
want it earlier.
****
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Did you read the reference I sent you? Since you’re obviously running the
ASCII version of QueryDosDevice (QueryDosDeviceA) in Srv03, it looks like
exactly your problem.
KB 931305 “Error message when you run a program that uses the
QueryDosDeviceA function: “ERROR_MORE_DATA””
http://support.microsoft.com/kb/931305
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Sunday, November 23, 2008 11:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] QueryDosDevice() failed
hi ken thanks for your reply
here is my code:-
#define MAX_BUF_QDD 8192
uint uiRepeatCnt = 1;
char *pszDosDeviceName = NULL;
pszDosDeviceName = (char*)malloc(MAX_BUF_QDD);
do
{
if(pszDosDeviceName == NULL)
{
FormatSystemError(IDS_SYSC_MALLOC, -1, FILE,
GetLastError(), MSGID_MALLOC, szLogMsg);
PrintLog(LEVEL0, SYSERR, szLogMsg);
return FALSE;
}
memset(pszDosDeviceName, 0, MAX_BUF_QDD * uiRepeatCnt);
dwRet = QueryDosDevice(NULL, pszDosDeviceName, (MAX_BUF_QDD
* uiRepeatCnt));
if(dwRet == 0)
{
if(ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
uiRepeatCnt++;
pszDosDeviceName =
(char*)realloc(pszDosDeviceName,MAX_BUF_QDD * uiRepeatCnt);
continue;
}
break;
}
}while(dwRet == 0);
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Although I agree with most of your comments, they are a matter of style, not
substance.
If he’s using the ANSI version of the libraries, then QueryDosDevice ==
QueryDosDeviceA, and TCHAR == char and LPTSTR == char *.
Also if you look closely, he is indeed doubling the size of the buffer on
ERROR_INSUFFICIENT_BUFFER, then tripling it, etc. It’s not the cause of his
problem.
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph M. Newcomer
Sent: Monday, November 24, 2008 4:58 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
I didn’t see the original post, but I see many problems with this code…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Sunday, November 23, 2008 11:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] QueryDosDevice() failed
hi ken thanks for your reply
here is my code:-
#define MAX_BUF_QDD 8192
uint uiRepeatCnt = 1;
char *pszDosDeviceName = NULL;
****
You are using an obsolete data type, ‘char’, to represent text. The data
type for the QueryDosDevice call is CLEARLY specified as LPTSTR, and it
makes little sense to use char, which is inconsistent with the specification
of the API. User-level code should always be written as Unicode-aware.
This is 2008.
LPTSTR pszDosDeviceName = NULL;
****
pszDosDeviceName = (char*)malloc(MAX_BUF_QDD);
****
pszDosDeviceName = (LPTSTR)malloc(MAX_BUF_QDD * sizeof(TCHAR);
****
do
{
if(pszDosDeviceName == NULL)
{
FormatSystemError(IDS_SYSC_MALLOC, -1, FILE,
GetLastError(), MSGID_MALLOC, szLogMsg);
PrintLog(LEVEL0, SYSERR, szLogMsg);
return FALSE;
}
memset(pszDosDeviceName, 0, MAX_BUF_QDD * uiRepeatCnt);
****
ZeroMemory(pszDosDeviceName, MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
It is not at all clear why this buffer needs to be zeroed at all. Why
bother?
****
dwRet = QueryDosDevice(NULL, pszDosDeviceName, (MAX_BUF_QDD
* uiRepeatCnt));
****
This is actually incorrect code, because it is passing a char* pointer to a
parameter which is clearly specified as LPTSTR
****
if(dwRet == 0)
{
if(ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
uiRepeatCnt++;
****
Note also that the typical technique is to double the buffer size each time,
rather than incrementing by a simple integer multiple.
****
pszDosDeviceName =
(char*)realloc(pszDosDeviceName,MAX_BUF_QDD * uiRepeatCnt);
****
pszDosDeviceName = (LPTSTR)realloc(pszDosDeviceName,
MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
****
continue;
}
break;
****
Why not just free the buffer and return FALSE?
****
}
}while(dwRet == 0);
***
This is an odd construct for a loop. Why not just while(TRUE) and break as
appropriate. A do-while loop is hard to reason about.
I used code similar to this and created a program that actually works, and
returns a valid set of information. I expect that it will be available for
download from my Web site within a day or two. It generates a correct list
of all devices. Send me private email to get the complete source if you
want it earlier.
****
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Well, using char is considered poor style. I didn’t see what the problem
was, but I was able to successfully execute it.
The doubling/tripling/quadrupling is not the usual technique; doubling each
time (*2, *4, *8, *16) is the usual idiom, and is usually considered the
better approach, that is len *= 2 or uiCount *= 2 each time through the
loop.
But I didn’t have any problems executing similar code, so I need to know
what the original problem statement was, which I said I didn’t see. So I
just wrote the code and it ran perfectly.
joe
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ken Cross
Sent: Monday, November 24, 2008 8:36 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
Although I agree with most of your comments, they are a matter of style, not
substance.
If he’s using the ANSI version of the libraries, then QueryDosDevice ==
QueryDosDeviceA, and TCHAR == char and LPTSTR == char *.
Also if you look closely, he is indeed doubling the size of the buffer on
ERROR_INSUFFICIENT_BUFFER, then tripling it, etc. It’s not the cause of his
problem.
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph M. Newcomer
Sent: Monday, November 24, 2008 4:58 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
I didn’t see the original post, but I see many problems with this code…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Sunday, November 23, 2008 11:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] QueryDosDevice() failed
hi ken thanks for your reply
here is my code:-
#define MAX_BUF_QDD 8192
uint uiRepeatCnt = 1;
char *pszDosDeviceName = NULL;
****
You are using an obsolete data type, ‘char’, to represent text. The data
type for the QueryDosDevice call is CLEARLY specified as LPTSTR, and it
makes little sense to use char, which is inconsistent with the specification
of the API. User-level code should always be written as Unicode-aware.
This is 2008.
LPTSTR pszDosDeviceName = NULL;
****
pszDosDeviceName = (char*)malloc(MAX_BUF_QDD);
****
pszDosDeviceName = (LPTSTR)malloc(MAX_BUF_QDD * sizeof(TCHAR);
****
do
{
if(pszDosDeviceName == NULL)
{
FormatSystemError(IDS_SYSC_MALLOC, -1, FILE,
GetLastError(), MSGID_MALLOC, szLogMsg);
PrintLog(LEVEL0, SYSERR, szLogMsg);
return FALSE;
}
memset(pszDosDeviceName, 0, MAX_BUF_QDD * uiRepeatCnt);
****
ZeroMemory(pszDosDeviceName, MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
It is not at all clear why this buffer needs to be zeroed at all. Why
bother?
****
dwRet = QueryDosDevice(NULL, pszDosDeviceName, (MAX_BUF_QDD
* uiRepeatCnt));
****
This is actually incorrect code, because it is passing a char* pointer to a
parameter which is clearly specified as LPTSTR
****
if(dwRet == 0)
{
if(ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
uiRepeatCnt++;
****
Note also that the typical technique is to double the buffer size each time,
rather than incrementing by a simple integer multiple.
****
pszDosDeviceName =
(char*)realloc(pszDosDeviceName,MAX_BUF_QDD * uiRepeatCnt);
****
pszDosDeviceName = (LPTSTR)realloc(pszDosDeviceName,
MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
****
continue;
}
break;
****
Why not just free the buffer and return FALSE?
****
}
}while(dwRet == 0);
***
This is an odd construct for a loop. Why not just while(TRUE) and break as
appropriate. A do-while loop is hard to reason about.
I used code similar to this and created a program that actually works, and
returns a valid set of information. I expect that it will be available for
download from my Web site within a day or two. It generates a correct list
of all devices. Send me private email to get the complete source if you
want it earlier.
****
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Yeah, I wish people would include the full email stream - it doesn’t get
*that* big if it’s plain text.
Here was the original problem:
Hello everyone!!
I want to find out all the devices attach to the system. So i am using
“QueryDosDevice()” API to get all the devices name. “QueryDosDevice()” is
working correctly on almost all systems. But one of the system with
configuration
OS:windows server 2003 with x64bit processor “QueryDosDevice()” API has
started failing.
GetLastError is returning the error code: 234 which is “ERROR_MORE_DATA”.
Whether any one is having any idea what could be wrong here??
any help will be greatly appriciated.
thanks in advance.
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph M. Newcomer
Sent: Monday, November 24, 2008 10:29 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
Well, using char is considered poor style. I didn’t see what the problem
was, but I was able to successfully execute it.
The doubling/tripling/quadrupling is not the usual technique; doubling each
time (*2, *4, *8, *16) is the usual idiom, and is usually considered the
better approach, that is len *= 2 or uiCount *= 2 each time through the
loop.
But I didn’t have any problems executing similar code, so I need to know
what the original problem statement was, which I said I didn’t see. So I
just wrote the code and it ran perfectly.
joe
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ken Cross
Sent: Monday, November 24, 2008 8:36 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
Although I agree with most of your comments, they are a matter of style, not
substance.
If he’s using the ANSI version of the libraries, then QueryDosDevice ==
QueryDosDeviceA, and TCHAR == char and LPTSTR == char *.
Also if you look closely, he is indeed doubling the size of the buffer on
ERROR_INSUFFICIENT_BUFFER, then tripling it, etc. It’s not the cause of his
problem.
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph M. Newcomer
Sent: Monday, November 24, 2008 4:58 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
I didn’t see the original post, but I see many problems with this code…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Sunday, November 23, 2008 11:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] QueryDosDevice() failed
hi ken thanks for your reply
here is my code:-
#define MAX_BUF_QDD 8192
uint uiRepeatCnt = 1;
char *pszDosDeviceName = NULL;
****
You are using an obsolete data type, ‘char’, to represent text. The data
type for the QueryDosDevice call is CLEARLY specified as LPTSTR, and it
makes little sense to use char, which is inconsistent with the specification
of the API. User-level code should always be written as Unicode-aware.
This is 2008.
LPTSTR pszDosDeviceName = NULL;
****
pszDosDeviceName = (char*)malloc(MAX_BUF_QDD);
****
pszDosDeviceName = (LPTSTR)malloc(MAX_BUF_QDD * sizeof(TCHAR);
****
do
{
if(pszDosDeviceName == NULL)
{
FormatSystemError(IDS_SYSC_MALLOC, -1, FILE,
GetLastError(), MSGID_MALLOC, szLogMsg);
PrintLog(LEVEL0, SYSERR, szLogMsg);
return FALSE;
}
memset(pszDosDeviceName, 0, MAX_BUF_QDD * uiRepeatCnt);
****
ZeroMemory(pszDosDeviceName, MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
It is not at all clear why this buffer needs to be zeroed at all. Why
bother?
****
dwRet = QueryDosDevice(NULL, pszDosDeviceName, (MAX_BUF_QDD
* uiRepeatCnt));
****
This is actually incorrect code, because it is passing a char* pointer to a
parameter which is clearly specified as LPTSTR
****
if(dwRet == 0)
{
if(ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
uiRepeatCnt++;
****
Note also that the typical technique is to double the buffer size each time,
rather than incrementing by a simple integer multiple.
****
pszDosDeviceName =
(char*)realloc(pszDosDeviceName,MAX_BUF_QDD * uiRepeatCnt);
****
pszDosDeviceName = (LPTSTR)realloc(pszDosDeviceName,
MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
****
continue;
}
break;
****
Why not just free the buffer and return FALSE?
****
}
}while(dwRet == 0);
***
This is an odd construct for a loop. Why not just while(TRUE) and break as
appropriate. A do-while loop is hard to reason about.
I used code similar to this and created a program that actually works, and
returns a valid set of information. I expect that it will be available for
download from my Web site within a day or two. It generates a correct list
of all devices. Send me private email to get the complete source if you
want it earlier.
****
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Looks like the MBCS article may be the secret. I did it in Unicode, because
I don’t believe in writing ANSI apps. It is up on
www.flounder.com/querydosdevice.htm
joe
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ken Cross
Sent: Monday, November 24, 2008 11:57 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
Yeah, I wish people would include the full email stream - it doesn’t get
*that* big if it’s plain text.
Here was the original problem:
Hello everyone!!
I want to find out all the devices attach to the system. So i am using
“QueryDosDevice()” API to get all the devices name. “QueryDosDevice()” is
working correctly on almost all systems. But one of the system with
configuration
OS:windows server 2003 with x64bit processor “QueryDosDevice()” API has
started failing.
GetLastError is returning the error code: 234 which is “ERROR_MORE_DATA”.
Whether any one is having any idea what could be wrong here??
any help will be greatly appriciated.
thanks in advance.
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph M. Newcomer
Sent: Monday, November 24, 2008 10:29 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
Well, using char is considered poor style. I didn’t see what the problem
was, but I was able to successfully execute it.
The doubling/tripling/quadrupling is not the usual technique; doubling each
time (*2, *4, *8, *16) is the usual idiom, and is usually considered the
better approach, that is len *= 2 or uiCount *= 2 each time through the
loop.
But I didn’t have any problems executing similar code, so I need to know
what the original problem statement was, which I said I didn’t see. So I
just wrote the code and it ran perfectly.
joe
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ken Cross
Sent: Monday, November 24, 2008 8:36 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
Although I agree with most of your comments, they are a matter of style, not
substance.
If he’s using the ANSI version of the libraries, then QueryDosDevice ==
QueryDosDeviceA, and TCHAR == char and LPTSTR == char *.
Also if you look closely, he is indeed doubling the size of the buffer on
ERROR_INSUFFICIENT_BUFFER, then tripling it, etc. It’s not the cause of his
problem.
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph M. Newcomer
Sent: Monday, November 24, 2008 4:58 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] QueryDosDevice() failed
I didn’t see the original post, but I see many problems with this code…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Sunday, November 23, 2008 11:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] QueryDosDevice() failed
hi ken thanks for your reply
here is my code:-
#define MAX_BUF_QDD 8192
uint uiRepeatCnt = 1;
char *pszDosDeviceName = NULL;
****
You are using an obsolete data type, ‘char’, to represent text. The data
type for the QueryDosDevice call is CLEARLY specified as LPTSTR, and it
makes little sense to use char, which is inconsistent with the specification
of the API. User-level code should always be written as Unicode-aware.
This is 2008.
LPTSTR pszDosDeviceName = NULL;
****
pszDosDeviceName = (char*)malloc(MAX_BUF_QDD);
****
pszDosDeviceName = (LPTSTR)malloc(MAX_BUF_QDD * sizeof(TCHAR);
****
do
{
if(pszDosDeviceName == NULL)
{
FormatSystemError(IDS_SYSC_MALLOC, -1, FILE,
GetLastError(), MSGID_MALLOC, szLogMsg);
PrintLog(LEVEL0, SYSERR, szLogMsg);
return FALSE;
}
memset(pszDosDeviceName, 0, MAX_BUF_QDD * uiRepeatCnt);
****
ZeroMemory(pszDosDeviceName, MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
It is not at all clear why this buffer needs to be zeroed at all. Why
bother?
****
dwRet = QueryDosDevice(NULL, pszDosDeviceName, (MAX_BUF_QDD
* uiRepeatCnt));
****
This is actually incorrect code, because it is passing a char* pointer to a
parameter which is clearly specified as LPTSTR
****
if(dwRet == 0)
{
if(ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
uiRepeatCnt++;
****
Note also that the typical technique is to double the buffer size each time,
rather than incrementing by a simple integer multiple.
****
pszDosDeviceName =
(char*)realloc(pszDosDeviceName,MAX_BUF_QDD * uiRepeatCnt);
****
pszDosDeviceName = (LPTSTR)realloc(pszDosDeviceName,
MAX_BUF_QDD * uiRepeatCnt * sizeof(TCHAR));
****
continue;
}
break;
****
Why not just free the buffer and return FALSE?
****
}
}while(dwRet == 0);
***
This is an odd construct for a loop. Why not just while(TRUE) and break as
appropriate. A do-while loop is hard to reason about.
I used code similar to this and created a program that actually works, and
returns a valid set of information. I expect that it will be available for
download from my Web site within a day or two. It generates a correct list
of all devices. Send me private email to get the complete source if you
want it earlier.
****
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Thanks all of you for your valuable comments
i came to know a lot from all the above discussion.
i red the article
http://support.microsoft.com/kb/931305
and its really help me a lot. Also i really understant now the hazards of writing ANSI App.
So now i am changing my code form ANSI to Unicode.
thanks everybody!!!