資源描述:
《C#調(diào)用windows的API函數(shù)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;usingSystem.Threading;usingSystem.Collections;usingSystem.IO;//以下是調(diào)用windows的API的函數(shù)//獲得G
2、UID[DllImport("hid.dll")]publicstaticexternvoidHidD_GetHidGuid(refGuidHidGuid);GuidguidHID=Guid.Empty;//過(guò)濾設(shè)備,獲取需要的設(shè)備[DllImport("setupapi.dll",SetLastError=true)]publicstaticexternIntPtrSetupDiGetClassDevs(refGuidClassGuid,uintEnumerator,IntPtrHwndParent,DIGCFFlags);IntPtrhD
3、evInfo;//獲取設(shè)備,true獲取到[DllImport("setupapi.dll",CharSet=CharSet.Auto,SetLastError=true)]publicstaticexternBooleanSetupDiEnumDeviceInterfaces(IntPtrhDevInfo,IntPtrdevInfo,refGuidinterfaceClassGuid,UInt32memberIndex,refSP_DEVICE_INTERFACE_DATAdeviceInterfaceData);publicstructS
4、P_DEVICE_INTERFACE_DATA{publicintcbSize;publicGuidinterfaceClassGuid;publicintflags;publicintreserved;}//獲取接口的詳細(xì)信息必須調(diào)用兩次第1次返回長(zhǎng)度第2次獲取數(shù)據(jù)[DllImport("setupapi.dll",SetLastError=true,CharSet=CharSet.Auto)]privatestaticexternboolSetupDiGetDeviceInterfaceDetail(IntPtrdeviceInfoSet
5、,refSP_DEVICE_INTERFACE_DATAdeviceInterfaceData,IntPtrdeviceInterfaceDetailData,intdeviceInterfaceDetailDataSize,refintrequiredSize,SP_DEVINFO_DATAdeviceInfoData);[StructLayout(LayoutKind.Sequential)]publicclassSP_DEVINFO_DATA{publicintcbSize=Marshal.SizeOf(typeof(SP_DEVINF
6、O_DATA));publicGuidclassGuid=Guid.Empty;//temppublicintdevInst=0;//dumypublicintreserved=0;}[StructLayout(LayoutKind.Sequential,Pack=2)]internalstructSP_DEVICE_INTERFACE_DETAIL_DATA{internalintcbSize;internalshortdevicePath;}publicenumDIGCF{DIGCF_DEFAULT=0x1,DIGCF_PRESENT=0
7、x2,DIGCF_ALLCLASSES=0x4,DIGCF_PROFILE=0x8,DIGCF_DEVICEINTERFACE=0x10}//獲取設(shè)備文件[DllImport("kernel32.dll",SetLastError=true)]privatestaticexternintCreateFile(stringlpFileName,//filenameuintdwDesiredAccess,//accessmodeuintdwShareMode,//sharemodeuintlpSecurityAttributes,//SDuint
8、dwCreationDisposition,//howtocreateuintdwFlagsAndAttributes,//fileattributesuinthT