예제 #1
0
 public static extern bool SetupDiGetSelectedDriver(IntPtr DeviceInfoSet, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData, ref InstallMainClass.SP_DRVINFO_DATA DriverInfoData);
예제 #2
0
        private bool RegisterModem(IntPtr hdi, ref InstallMainClass.SP_DEVINFO_DATA pdevData, string Port, string AT, string MaximumPortSpeed)
        {
            this.print(">>正在注册Modem.........!");
            string str = "AttachedTo";
            int    num = 0;

            InstallMainClass.SP_DRVINFO_DATA sPDRVINFODATum = new InstallMainClass.SP_DRVINFO_DATA();
            uint num1 = 0;

            InstallMainClass.SP_DEVINFO_DATA sPDEVINFODATum = new InstallMainClass.SP_DEVINFO_DATA();
            this.print(">>注册设备信息.........!");
            if (InstallMainClass.SetupDiRegisterDeviceInfo(hdi, ref pdevData, 0, ref num1, ref num, ref sPDEVINFODATum))
            {
                this.print(">>注册设备信息成功!");
                IntPtr intPtr = InstallMainClass.SetupDiOpenDevRegKey(hdi, ref pdevData, 1, 0, 2, 0xf003f);
                if ((int)intPtr != -1 || InstallMainClass.GetLastError() != 0xe0000204)
                {
                    return(false);
                }
                else
                {
                    intPtr = InstallMainClass.SetupDiCreateDevRegKey(hdi, ref pdevData, 1, 0, 2, (IntPtr)0, null);
                    if (-1 != (int)intPtr)
                    {
                        this.print(string.Concat(">>正在绑定端口到", Port));
                        byte[] bytes = Encoding.ASCII.GetBytes(Port);
                        if (InstallMainClass.RegSetValueEx(intPtr, str, 0, 1, bytes, (uint)bytes.Length) == 0)
                        {
                            this.print(">>绑定端口成功");
                            this.print(">>正在初始化AT指今....");
                            if (AT != "")
                            {
                                byte[] numArray = Encoding.ASCII.GetBytes(AT);
                                if (InstallMainClass.RegSetValueEx(intPtr, "UserInit", 0, 1, numArray, (uint)numArray.Length) != 0)
                                {
                                    this.print(">>初始化AT指今失败", 3);
                                    return(false);
                                }
                            }
                            this.print(">>初始化AT指今成功");
                            this.print(">>正在设置最大端口速率....");
                            byte[] bytes1 = Encoding.ASCII.GetBytes(MaximumPortSpeed);
                            if (InstallMainClass.RegSetValueEx(intPtr, "MaximumPortSpeed", 0, 4, bytes1, (uint)bytes1.Length) == 0)
                            {
                                this.print(">>设置最大端口速率成功");
                                InstallMainClass.RegCloseKey(intPtr);
                                this.print(">>注册表相关健已关闭");
                                num1           = 0;
                                num            = 0;
                                sPDEVINFODATum = new InstallMainClass.SP_DEVINFO_DATA();
                                if (InstallMainClass.SetupDiRegisterDeviceInfo(hdi, ref pdevData, 0, ref num1, ref num, ref sPDEVINFODATum))
                                {
                                    this.print(">>注册Modem成功");
                                    InstallMainClass.SetupDiGetSelectedDriver(hdi, ref pdevData, ref sPDRVINFODATum);
                                    return(true);
                                }
                                else
                                {
                                    this.print(">>注册Modem失败", 3);
                                    return(false);
                                }
                            }
                            else
                            {
                                this.print(">>设置最大端口速率失败", 3);
                                return(false);
                            }
                        }
                        else
                        {
                            this.print(">>绑定端口失败", 3);
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                this.print(">>注册设备信息失败!");
                return(false);
            }
        }