|
kcynic wrote: .When I scan a USB device plugged,I want to get its driver letter like G,H,and so on.For example,i get a device instance like "USB\VID_0AC8&PID_301B\5&37FD04DB&0&2"
Now through which mehtod ur detecting the USB is plugged? WM_DEVICECHANGE?
|
|
|
|
|
No,I only retrieve the USB device by accessing all the usb hub port to see whether there are some USB devices plugged in.
|
|
|
|
|
When a USB device is plugged, all the top level windows will receive a WM_DEVICECHANGE message. An in such case you can retrive the drive letter from the structure pointed by the LPARAM of that message. Check the MSDN for the help of WM_DEVICECHANGE.
|
|
|
|
|
And my program is not a GUI project,only a console project,because there is no need to retrieve windows messages.In fact,my program would be run when the USB devices had been plugged in.By now,if there only has one specified USB device,my program works well,and if there are more than one such USB device,it does not know which USB device it really want to operate.(In addition,one such USB device can be treate as a mass storage.
|
|
|
|
|
ok. I can help u with the first task( calling the ZwOpenFile() and ZwQueryInformationFile()).
1 . copy all the necessary structure for those function from the ntddk.h file to ur local file
2. now create a pointer for that function. like
typedef NTSTATUS (*pZwOpenFile)(<br />
OUT PHANDLE FileHandle,<br />
IN ACCESS_MASK DesiredAccess,<br />
IN POBJECT_ATTRIBUTES ObjectAttributes,<br />
OUT PIO_STATUS_BLOCK IoStatusBlock,<br />
IN ULONG ShareAccess,<br />
IN ULONG OpenOptions<br />
);
3. Now use LoadLibrary to load the ntdll.dll. HMODULE hModule = LoadLibrary( _T("ntdll.dll"));
4. Now call GetProcAddress() function to get of the ZwOpenFile function.
pZwOpenFile ZwOpenFile = (pZwOpenFile )GetProcAddress( hModule, "ZwOpenFile" );
now u can call ZwOpenFile like any other functions.
|
|
|
|
|
Yes,that is a good idea.
And if you known some about the 2nd question?
Thank you very much.
|
|
|
|
|
|
Yes,perhaps that can.
But I tried several times of the IOCTL_SCSI_GET_INQUIRY_DATA.But it faild for every of my USB stroage except my IDE storage.
I search the reason on the internet,someone said that,that ioctl would faild for usb device,but use SCSI_INQUIRY(operation code:0x12h) command to the device.
But I am not a driver programmer,I only a application programmer,so I only know a little about WDM.
I do not know how to do such task.
|
|
|
|
|
did u search in google. I found some sample that use SCSI_INQUIRY. One of them here[^]
|
|
|
|
|
In fact,not because I am lazy.I am a Chinese,so I read English a little slowly.On the other side,in my local area,the search engine will list the linkers in my own language priority.
By now,I do not know the liker you given to me works well or not,but I will have a try.
And I will learn English more hard.I can see,I will read English words as fast as reading my own language.
Thank you very much.
BEST WISHES.
|
|
|
|
|
Repost of my answer in our earlier discussion, just so it is complete in the archives:
You can do this without using the functions from wdm and ntddk. After you get your device's name using the SetupDi functions, open a handle using CreateFile . Then use DeviceIoControl to send the IOCTL_SCSI_GET_INQUIRY_DATA to the device. Google on that IOCTL and you'll find some examples of calling it from user mode.
Judy
(fixed my cut-and-paste HTML)
modified on Tuesday, December 18, 2007 1:29:05 PM
|
|
|
|
|
Is there a C++ funtion like GetSystemDrive? Basically what I want is a way to get the system drive letter into a string.
This is sort of like What I want to do.
char BUFF[MAX_PATH] = {NULL};
GetWindowsDirectory(BUFF, MAX_PATH);
strcat(BUFF, "\\whatever\\Register.bat");
That would create a string "C:\windows\whatever\Register.bat"
What I really want is to create a string like this
"C:\whatever\Register.bat"
I just need a way to get the systems drive letter.
Any help would be appreciated.
|
|
|
|
|
Well I'm answering my own question. I used Getenv("systemdrive")
char * BUFF;
BUFF = getenv ("SYSTEMDRIVE");
strcat( BUFF, "\\whatever\\Register.bat");
This produced C:\whatever\register.bat
|
|
|
|
|
It is not safe to modify the value of the environment variable using the returned pointer.
By MSDN
|
|
|
|
|
Just take the drive letter returned from GetWindowsDirectory() .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am trying to get a small Windows program to follow the example in http://msdn2.microsoft.com/en-us/library/ms533844.aspx , which reads an image from a .BMP and writes it to a .JPG . I have got it to compile, except for one persistent error: "'GetEncoderClsid': identifier not found". (This is the line afer the comment "// Get the CLSID of the JPEG encoder.".) Please, is this name GetEncoderClsid mistyped in the original? or what? Thanks.
|
|
|
|
|
did you forget to forward declare it before the main() function ?
INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
or you didn't didn't include the function implementation, which is shown on a link above the code :
"The main function relies on the helper function GetEncoderClsid, which is shown in Retrieving the Class Identifier for an Encoder[^]"
|
|
|
|
|
Thanks. I inserted the line
INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid); // helper function
and it caused successful compilation but this link error:
unresolved external symbol "int __cdecl GetEncoderClsid(wchar_t const *,struct _GUID *)" (?GetEncoderClsid@@YAHPB_WPAU_GUID@@@Z) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
|
|
|
|
|
YES !
follow the link[^] I gave you, which I got from you original link. the code of the method is there. copy it and paste it in your project.
|
|
|
|
|
Thanks. It worked!!!!!!!!!!!!!!. It copied a BMP file to a JPG file with modew conversion, like I wanted. Thanks everybody.
|
|
|
|
|
Anthony Appleyard wrote: Thanks everybody
man, I was alone on this thread
BTW, please read the WHOLE page after now, because I didn't invent anything. all you need was provided in the first related link.
|
|
|
|
|
toxcct wrote: because I didn't invent anything.
Ahh, don't be so modest, Tox. We all know that your middle name is bmp-to-jpg.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
I have the free version of Visual C++ 2008.
In reply to this query, you told me to read http://msdn2.microsoft.com/en-us/library/ms533798.aspx about GDI+.
I went from there to its subpage about "Setting JPEG Compression Level", which has an example coding. Thus, I first inserted the line
#include <gdiplus.h>
in a small test program. The result was 104 compile errors and 8 warnings, of which the first were:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(74) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
...\include\gdiplusimaging.h(74) : error C2440: 'initializing' : cannot convert from 'const char [37]' to 'int'
1> There is no context in which this conversion is possible
...\include\gdiplusimaging.h(74) : error C2146: syntax error : missing ';' before identifier 'IImageBytes'
...include\gdiplusimaging.h(74) : error C2470: 'IImageBytes' : looks like a function definition, but there is no parameter list; skipping apparent body
...\include\gdiplusimaging.h(74) : error C2059: syntax error : 'public'
...\include\gdiplusimaging.h(280) : error C2146: syntax error : missing ';' before identifier 'id'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please, what should I do now?
|
|
|
|
|
I inserted #include (less-than-sign) gdiplus.h (greater-than-sign) :: the %^&*&* vagaries of HTLM code.
|
|
|
|