Get USB device parent or descendant

Source: Internet
Author: User

/// <summary>        ///Get device Parent/// </summary>        /// <param name= "Driver" ></param>        /// <returns></returns>        Private Static BOOLTrygetdriveridparent (stringDriver out stringResultdeviceid) {Resultdeviceid=""; Try            {                intCm_locate_devnode_normal =0x00000000; intCr_success =0x00000000;                UInt32 Parentinst; intCurinst =0; intPlen =0; intApiresult = Win32.cm_locate_devnodea (refcurinst, driver, cm_locate_devnode_normal); if(Apiresult! =cr_success) {                    return false; } Apiresult= Win32.cm_get_parent ( outParentinst, (UInt32) curinst, cm_locate_devnode_normal); if(Apiresult! =cr_success) {                    return false; } Apiresult= Win32.cm_get_device_id_size ( outPlen, Parentinst, cm_locate_devnode_normal); if(Apiresult! =cr_success) {                    return false; }                Char[] Ptrinstancebuf =New Char[ -]; //get Device ID string addressApiresult = win32.cm_get_device_id (Parentinst, Ptrinstancebuf, Plen,0); if(Apiresult! =cr_success) {                    return false; } Resultdeviceid=New string(PTRINSTANCEBUF); return true; }            Catch(Exception ecexception) {Loghelper.writeerrorlog ("Get Parent"+ecexception.message, ecexception); return false; }} [DllImport ("Setupapi.dll", SetLastError =true)]         Public Static extern intCm_locate_devnodea (ref intPdndevinst,stringPdeviceid,intulflags); [DllImport ("Setupapi.dll")]         Public Static extern intCm_get_parent ( outUInt32 Pdndevinst, UInt32 dndevinst,intulflags); [DllImport ("Setupapi.dll", SetLastError =true)]         Public Static extern intCm_get_device_id_size ( out intPullen, UInt32 Dndevinst,intFlags =0); [DllImport ("Setupapi.dll", CharSet =CharSet.Unicode)] Public Static extern intcm_get_device_id (UInt32 Dndevinst,Char[] Buffer,intBufferlen,intFlags);

Get USB device parent or descendant

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.