| 发表于:2007-03-06 14:30:121楼 得分:20 |
from http://www.devmedia.com.br/articles/viewcomp.asp?comp=4092&hl= 先看看别人是怎么用的 public const int digcf_present = 2; public const int dif_propertychange = 0x00000012; public const int dics_flag_global = 0x00000001; public const int invalid_handle_value = -1; public const int dics_enable = 0x00000001; public const int dics_disable = 0x00000002; public const string usbvidpid = @ "usb\vid_0403&pid_6001\a1000pra "; [structlayout(layoutkind.sequential)] public struct sp_classinstall_header { public int cbsize; public int installfunction; } [structlayout(layoutkind.sequential)] public struct sp_propchange_params { public sp_classinstall_header classinstallheader; public int statechange; public int scope; public int hwprofile; public void init() { classinstallheader = new sp_classinstall_header(); } } [structlayout(layoutkind.sequential)] public struct sp_devinfo_data { public int cbsize; public guid classguid; public int devinst; public int reserved; } [dllimport( "setupapi.dll ")] public static extern bool setupdienumdeviceinfo( intptr deviceinfoset, int supplies, ref sp_devinfo_data deviceinfodata); [dllimport( "setupapi.dll ")] public static extern bool setupdisetclassinstallparams( intptr deviceinfoset, ref sp_devinfo_data deviceinfodata, ref sp_classinstall_header classinstallparams, int classinstallparamssize); [dllimport( "setupapi.dll ")] public static extern bool setupdicallclassinstaller( int installfunction, intptr deviceinfoset, ref sp_devinfo_data deviceinfodata); static bool statechange(int newstate, int selecteditem, intptr hdevinfo) { sp_propchange_params propchangeparams; sp_devinfo_data deviceinfodata; propchangeparams = new sp_propchange_params(); propchangeparams.init(); deviceinfodata = new sp_devinfo_data(); propchangeparams.classinstallheader.cbsize = marshal.sizeof(propchangeparams.classinstallheader); deviceinfodata.cbsize = marshal.sizeof(deviceinfodata); if (!setupdienumdeviceinfo(hdevinfo, selecteditem, ref deviceinfodata)) return false; propchangeparams.classinstallheader.installfunction = dif_propertychange; propchangeparams.scope = dics_flag_global; propchangeparams.statechange = newstate; if (!setupdisetclassinstallparams( hdevinfo, ref deviceinfodata, ref propchangeparams.classinstallheader, (int)marshal.sizeof(propchangeparams))) return false; if (!setupdicallclassinstaller( dif_propertychange, hdevinfo, ref deviceinfodata)) return false; return true; } | | |
|