Thanks, I'll try that. Even when it fails in one way or another - it generally "returns" GUID ( I am not that far in my coding effords to identify the GUID ) when I ask for all devices.
I also folowed your advice ( and MS) to use // Pass hRes to FormatMessage() to retrieve the error message HRESULT hRes = HRESULT_FROM_SETUPAPI(::GetLastError()); and it did not change the error formated message.
Thanks Cristian, I have actually given up on figuring it out, but here is the latest ( with lots of development comments) and it does work as advertized. NULL, // (PBYTE)buf, // get size with NULL (PBYTE)buffer, // _Out_opt_ PBYTE PropertyBuffer, 0, // sizeof(buf), With these two parameters set this way , the function fails and returns / sets the &nSize.
I am not checking the errors anymore and just run the same function again with results and it returns true.
The rest of it is just an execise to see the “properties” . And it works.
I am going to check my original code , it is possible that I did forget the cast (PBYTE) buffer, but it is such a mess I am really not looking forward to do that. I was just hoping to delete all the commented out attempts a be done with it. I'll check for unicode too. Thanks
There is one unanswered question - this function <b>SetupDiGetDeviceRegistryProperty</b>either returns description or friendly name. How am I suppose to know which one is really valid to ask for??? SetupDiGetDeviceRegistryProperty
The string_t is a string class, but you can replace it with std::wstring (or a LPWSTR* output variable as well). Same for vector_t, pair_t - you can replace them with STL counterparts std::vector, std::pair with minimal or no changes.
The getDescription is what you are looking for, which in turn calls getString - this is the core of business.
The usage - in my project - is:
You can use the code, sure - that's why I posted it.
A property string may or may not be defined, although I suppose to do not have description sounds odd from a vendor. SetupDiGetDeviceRegistryProperty can return FALSE, as the documentation says: SetupDiGetDeviceRegistryProperty returns the ERROR_INVALID_DATA error code if the requested property does not exist for a device or if the property data is not valid.
The code is resposing well, but it is usefull for file shreding, it uses WriteFile() to overwrite on the file.
For shredding a folder I must search the space of the folder & iterate this procedure for all files, and about the subfolder we need a recursive code to traverse them.
Is there any better solution to wipe a folder of shred a whole drive?
I thinked that the files of the folder could be deleted in this way and finally the empty folder that is not important can be deleted from the system instructions.
This idea is feasible, but the only concern is about the complexity for the huge folders with various subfolders; it is time consuming.
From the other responses presumably the following is what you want to do.
1. You want to shred files.
2. You want to shred file information in the directory itself.
For 1 you iterate over files in the directory and recurse through each sub directory and shred each file. You MUST do this. There is no magic solution that would allow you to do it in some other way.
For 2 it is more complex and depends on what you want you think a 'shred' would do. At a minor level you can just rename each file before shredding it. That overwrites the name. For a real shred you would need to
1. Create an API to access the file system at a raw level
2. Parse the file block
3. Shred the relevant file info that was found by step 1. In this case 'shred' includes the same basic methodology employed to shred a file but on a very small scale. You would need to write the shred code yourself.
Note that if you choose to implement the solution above then you MUST back up your hard drive because when you mess up the code you will need to reformat the hard drive. You must also extensively test this feature as well for the same reason. Also account for different file system types (like ssd and usb.)
PS: Sorry if my answer sounds a bit rude, but I am realy confused about the question what getchar does. If I were you, my first step would be asking google, bing are whatever searchmachine you want. Or taking a look inside a book. If I don't understand the description/answer there, I would ask in a forum again.