Jump to content
  • Advertisement
Sign in to follow this  

Unity Detecting an USB.

This topic is 4522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I have the same requirement as in the thread at http://www.gamedev.net/community/forums/topic.asp?topic_id=362845&whichpage=1� I wish to determine the type of removable drive, when the drive letter is given. To detect an USB (as per MSDN), I use the 'SetupDiGetDeviceRegistryProperty' method with SPDRP_REMOVAL_POLICY as a parameter. (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devinst_r/hh/DevInst_r/di-rtns_a60fa017-1c15-45bf-a178-37516bc0aea1.xml.asp) MSDN says: "SPDRP_REMOVAL_POLICY (Windows XP and later) The function retrieves the device's current removal policy as a DWORD containing one of the CM_REMOVAL_POLICY_Xxxx values defined in cfgmgr32.h." My problem: How does this function retrieve this value ? The Output parameter PropertyBuffer is of type PBYTE and when I type cast it and take the value as *((DWORD *)PropertyBuffer), it gives me an invalid value (some garbage other than the CM_REMOVAL_POLICY_ values defined in cfgmgr32.h) Can someone please help ?? Thanks, Vinoth

Share this post

Link to post
Share on other sites
You optimistically misunderstood the MSDN explanation.
Says an easily googled MSDN page:
Return Value

SetupDiGetDeviceRegistryProperty returns TRUE if the call was successful. Otherwise, it returns FALSE and the logged error can be retrieved with a call to GetLastError. 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.

So the return value is a generic status code; the important "result" is written into a team of output parameters:
Supplies a pointer to a variable to receive the data type of the property being retrieved. This is one of the standard registry data types.

Supplies a pointer to a buffer to receive the property being retrieved. If set to NULL, with PropertyBufferSize set to zero, the function just returns a value for RequiredSize.

Supplies the length, in bytes, of PropertyBuffer.

Optional. If not NULL, it is a caller-supplied pointer to a variable that receives the required size, in bytes, of the property buffer pointed to by PropertyBuffer, based on the property requested by Property.

Isn't it a cute API?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!