I have a problem to get information of connected USB Device.I am useing
OnMyDeviceChange(WPARAM wParam, LPARAM lParam);
function which is provide me all information.But when USB Device is connected all ready and my application is start after connecteion of USB Device then i havn't found any information of USB Device.Can any one give me advice to how to get connected USB Device information.Plz help me
i am useing both RegisterDeviceNotification and WM_DEVICECHANGE.And i am getting information when my application is running and USB Device is connect.But When my application is not running and USB drive is connected and my application is start after connection of USB Device then information is not showing.But USb Device is still connected.
So problem is that how to get information allready connection of USB Device.Plz help me
Your RegisterDeviceNotification[^] code is probably working correctly, however it will only detect changes while your application is running.
You failed to mention what type of USB device your application needs to enumerate. I will assume that you need all USB device types. You will essentially need to call SetupDiGetClassDevs[^] and pass the enumerator filter of "USB". Dont be frightened by the Windows Driver Kit references in the MSDN documentation. You will be able to use the SetupAPI without the DDK installed, although I believe you will need Platform SDK/Microsoft SDK.
OK, the classes depend on WTL, but I just tried some code an MFC dialog and started getting names of devices. I put this in OnInitDialog to test it as the first wizard generated comment shows. Try it. You'll need to #include devguid.h; and then put a break point on nMemberIndex++; and look at the name in szFriendlyName. After the first name go round the loop looking at the names.
I am trying to show single-frame/animated GIF images in a window created by 'CreateWindowEx'. I have used Image *, Graphics * (method DrawImage(Image *, INT, INT, INT, INT)) of GdiPlus dll. I used memry DC to avoid flickering. This was working fine.
Now the problem is that - When I add 2 commands /DYNAMICBASE and /NXCOMPAT in linker command line (VS 2005 project settings), the application simply crashes when trying to show any kind of GIF image. Although it is showing BMP, DIB, WMF, JPG, JPEG and TIFF images perfectly.
To see where the actual problem is i ran it in debug mode and find GdiPlus::Graphics::DrawImage fail to process. The Application Verifier 4.0 points that it is due to some bad address pointer. The astonishinig matter is that, in debug mode if I ignore the crash and click on 'Continue', the 'DrawImagw' returns StatusResult "Ok" and 'BitBilt' draws the image perfectly in my application window.
Thanks in advance, for helping me out of this situation.
Thanks for the suggesstion Xing. Since I am writting code in pur C++ and using Win32 APIs, I didn't found what is the exception class I should use to catch it. If you can suggest me, that'll be better for me.
Though i know, this is not a good approach, but here you can use this block to catch all the exception :-
// your drawing code here
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
Now, I find where the problem occurrs. It is nothing to do with the project setting /DYNAMICBASE or /NXCOMPAT in Linker command line.
The application only crashes if I run it with Application Verifier 4.0. Otherwise it is able to show (DrawImage) any kind of GIF image.
I am giving a part of the xml file generated by the Application Verifier 4.0. I hope it will help you to understand the error properly, which I could not resolve till now.
<avrf:logEntry Time="2009-04-15 : 12:18:56" LayerName="Heaps" StopCode="0x13" Severity="Error">
<avrf:message>First chance access violation for current stack trace.</avrf:message>
<avrf:parameter1>5960002 - Invalid address causing the exception.</avrf:parameter1>
<avrf:parameter2>4ed9b280 - Code address executing the invalid access.</avrf:parameter2>
<avrf:parameter3>129838 - Exception record.</avrf:parameter3>
<avrf:parameter4>129854 - Context record.</avrf:parameter4>
Many many thanks for your suggestion. I tried what both of you have said. But that was giving "error C2712: Cannot use __try in functions that require object unwinding" in my VS 2005. Anyway I solved that error by setting "Enable C++ Exceptions" to "No". Now I can track the exception, though generating too many warnings at compile time (for disabling C++ exceptions). So, the application doesn't crashes anymore.
Anyway, I need to show the GIF images. So, how can I do that after getting that exception - EXCEPTION_EXECUTE_HANDLER. What should I do
Thanks for your enthuasism, what you and Hamid have shown to my problem.
I used that __try-__exception() block. Inside that I call 'GetExceptionCode' API, which returns me the error code 0x80000003. It means EXCEPTION_BREAKPOINT (#define EXCEPTION_BREAKPOINT STATUS_BREAKPOINT in winbase.h). And in winnt.h STATUS_BREAKPOINT is defined as 0x80000003. So, right now I am here, back again in the square.
I don't understand what is the problem with Application Verifier 4.0. Without tracking by it, the application works fine.