// !! We strongly recommend that you read the "readme.txt" file in the sample code folder. // !! It contains important instructions on how to use the sample code using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace ChangeTest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button get_dongle_info; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox diag_filename; private System.Windows.Forms.Button write_diag_file; private System.Windows.Forms.Button do_update_code_string; private System.Windows.Forms.TextBox update_code_string; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button do_update_code_file; private System.Windows.Forms.TextBox update_code_file; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button restore_fd_lite; private System.Windows.Forms.Button get_machine_id; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox swkey_prod_code; private System.Windows.Forms.Button download_temp_swkey; private System.Windows.Forms.Button download_demo_swkey; private System.Windows.Forms.TextBox machine_id; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } // maximum number of USB devices that can be attached to a machine at any time public const int MAX_USB_DEVICES = 128; public const int MAX_PRODCODE_LEN = 9; // including terminating null public string AppName = "ChangeTest"; // mask values public const int TYPE_MASK_PRO = 1; public const int TYPE_MASK_FD = 2; public const int TYPE_MASK_ALL = (TYPE_MASK_PRO | TYPE_MASK_FD); public const int MODEL_MASK_LITE = 1; public const int MODEL_MASK_PLUS = 2; public const int MODEL_MASK_NET = 4; public const int MODEL_MASK_ALL = (MODEL_MASK_LITE | MODEL_MASK_PLUS | MODEL_MASK_NET); public const int MODEL_MASK_DEFAULT = (MODEL_MASK_PLUS | MODEL_MASK_NET); // type values for DCGetInfo (returned in the array) public const int TYPE_PRO = 1; public const int TYPE_FD = 2; // model values for DCGetInfo (returned in the array) public const int MODEL_LITE = 1; public const int MODEL_PLUS = 2; public const int MODEL_NET5 = 4; public const int MODEL_NETU = 7; // model values for DCDownloadDemoSoftwareKey public const int SWKEY_MODEL_DEFAULT = -1; // NB this assumes that the Demo Software Key Template was created with only one valid dongle model public const int SWKEY_MODEL_PRO_LITE = 0; public const int SWKEY_MODEL_PRO_PLUS = 1; public const int SWKEY_MODEL_PRO_NET = 2; public const int SWKEY_MODEL_FD_LITE = 3; public const int SWKEY_MODEL_FD_PLUS = 4; public const int SWKEY_MODEL_FD_NET = 5; private void InitializeComponent() { this.get_dongle_info = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.diag_filename = new System.Windows.Forms.TextBox(); this.write_diag_file = new System.Windows.Forms.Button(); this.do_update_code_string = new System.Windows.Forms.Button(); this.update_code_string = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.do_update_code_file = new System.Windows.Forms.Button(); this.update_code_file = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.restore_fd_lite = new System.Windows.Forms.Button(); this.get_machine_id = new System.Windows.Forms.Button(); this.machine_id = new System.Windows.Forms.TextBox(); this.download_temp_swkey = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.swkey_prod_code = new System.Windows.Forms.TextBox(); this.download_demo_swkey = new System.Windows.Forms.Button(); this.SuspendLayout(); // // get_dongle_info // this.get_dongle_info.Location = new System.Drawing.Point(48, 24); this.get_dongle_info.Name = "get_dongle_info"; this.get_dongle_info.Size = new System.Drawing.Size(224, 24); this.get_dongle_info.TabIndex = 0; this.get_dongle_info.Text = "Get Dongle Information"; this.get_dongle_info.Click += new System.EventHandler(this.get_dongle_info_Click); // // label1 // this.label1.Location = new System.Drawing.Point(16, 72); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(280, 16); this.label1.TabIndex = 1; this.label1.Text = "Enter diagnostic filename:"; // // diag_filename // this.diag_filename.Location = new System.Drawing.Point(16, 88); this.diag_filename.Name = "diag_filename"; this.diag_filename.Size = new System.Drawing.Size(288, 20); this.diag_filename.TabIndex = 2; this.diag_filename.Text = ""; // // write_diag_file // this.write_diag_file.Location = new System.Drawing.Point(48, 120); this.write_diag_file.Name = "write_diag_file"; this.write_diag_file.Size = new System.Drawing.Size(224, 24); this.write_diag_file.TabIndex = 3; this.write_diag_file.Text = "Write Diagnostics to File"; this.write_diag_file.Click += new System.EventHandler(this.write_diag_file_Click); // // label2 // this.label2.Location = new System.Drawing.Point(16, 168); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(280, 16); this.label2.TabIndex = 4; this.label2.Text = "Enter short Update Code here:"; // // update_code_string // this.update_code_string.Location = new System.Drawing.Point(16, 184); this.update_code_string.Name = "update_code_string"; this.update_code_string.Size = new System.Drawing.Size(288, 20); this.update_code_string.TabIndex = 5; this.update_code_string.Text = ""; // // do_update_code_string // this.do_update_code_string.Location = new System.Drawing.Point(48, 216); this.do_update_code_string.Name = "do_update_code_string"; this.do_update_code_string.Size = new System.Drawing.Size(224, 24); this.do_update_code_string.TabIndex = 6; this.do_update_code_string.Text = "Make Changes"; this.do_update_code_string.Click += new System.EventHandler(this.do_update_code_string_Click); // // do_update_code_file // this.do_update_code_file.Location = new System.Drawing.Point(48, 312); this.do_update_code_file.Name = "do_update_code_file"; this.do_update_code_file.Size = new System.Drawing.Size(224, 24); this.do_update_code_file.TabIndex = 9; this.do_update_code_file.Text = "Make Changes"; this.do_update_code_file.Click += new System.EventHandler(this.do_update_code_file_Click); // // update_code_file // this.update_code_file.Location = new System.Drawing.Point(16, 280); this.update_code_file.Name = "update_code_file"; this.update_code_file.Size = new System.Drawing.Size(288, 20); this.update_code_file.TabIndex = 8; this.update_code_file.Text = ""; // // label3 // this.label3.Location = new System.Drawing.Point(16, 264); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(280, 16); this.label3.TabIndex = 7; this.label3.Text = "Enter path to Update Code file:"; // // restore_fd_lite // this.restore_fd_lite.Location = new System.Drawing.Point(48, 368); this.restore_fd_lite.Name = "restore_fd_lite"; this.restore_fd_lite.Size = new System.Drawing.Size(224, 24); this.restore_fd_lite.TabIndex = 10; this.restore_fd_lite.Text = "Restore Dinkey FD Lite"; this.restore_fd_lite.Click += new System.EventHandler(this.restore_fd_lite_Click); // // get_machine_id // this.get_machine_id.Location = new System.Drawing.Point(16, 424); this.get_machine_id.Name = "get_machine_id"; this.get_machine_id.Size = new System.Drawing.Size(144, 24); this.get_machine_id.TabIndex = 11; this.get_machine_id.Text = "Get Machine ID"; this.get_machine_id.Click += new System.EventHandler(this.get_machine_id_Click); // // machine_id // this.machine_id.Location = new System.Drawing.Point(168, 424); this.machine_id.Name = "machine_id"; this.machine_id.Size = new System.Drawing.Size(136, 20); this.machine_id.TabIndex = 12; this.machine_id.Text = ""; // // download_temp_swkey // this.download_temp_swkey.Location = new System.Drawing.Point(48, 480); this.download_temp_swkey.Name = "download_temp_swkey"; this.download_temp_swkey.Size = new System.Drawing.Size(224, 24); this.download_temp_swkey.TabIndex = 13; this.download_temp_swkey.Text = "Download Temporary Software Key"; this.download_temp_swkey.Click += new System.EventHandler(this.download_temp_swkey_Click); // // label4 // this.label4.Location = new System.Drawing.Point(16, 528); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(280, 16); this.label4.TabIndex = 14; this.label4.Text = "Demo Software Key Product Code:"; // // swkey_prod_code // this.swkey_prod_code.Location = new System.Drawing.Point(16, 544); this.swkey_prod_code.Name = "swkey_prod_code"; this.swkey_prod_code.Size = new System.Drawing.Size(288, 20); this.swkey_prod_code.TabIndex = 15; this.swkey_prod_code.Text = ""; // // download_demo_swkey // this.download_demo_swkey.Location = new System.Drawing.Point(48, 576); this.download_demo_swkey.Name = "download_demo_swkey"; this.download_demo_swkey.Size = new System.Drawing.Size(224, 24); this.download_demo_swkey.TabIndex = 16; this.download_demo_swkey.Text = "Download Demo Software Key"; this.download_demo_swkey.Click += new System.EventHandler(this.download_demo_swkey_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(320, 624); this.Controls.Add(this.download_demo_swkey); this.Controls.Add(this.swkey_prod_code); this.Controls.Add(this.label4); this.Controls.Add(this.machine_id); this.Controls.Add(this.download_temp_swkey); this.Controls.Add(this.get_machine_id); this.Controls.Add(this.restore_fd_lite); this.Controls.Add(this.do_update_code_file); this.Controls.Add(this.update_code_file); this.Controls.Add(this.label3); this.Controls.Add(this.do_update_code_string); this.Controls.Add(this.update_code_string); this.Controls.Add(this.label2); this.Controls.Add(this.write_diag_file); this.Controls.Add(this.diag_filename); this.Controls.Add(this.label1); this.Controls.Add(this.get_dongle_info); this.Name = "Form1"; this.Text = "ChangeTest"; this.ResumeLayout(false); } /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } // routine to get & display information for all dongles attached private void get_dongle_info_Click(object sender, System.EventArgs e) { int ret_code, i, num_found; string DisplayString = null; string Type, Model, ProdCodeString; // return arrays of dongle details filedin by DCGetInfo int[] type = new int[MAX_USB_DEVICES]; int[] model = new int[MAX_USB_DEVICES]; byte[] prodcode = new Byte[MAX_USB_DEVICES*MAX_PRODCODE_LEN]; uint[] dongle_number = new uint[MAX_USB_DEVICES]; int[] update_number = new int[MAX_USB_DEVICES]; // find dongle information for all dongle types, Plus & Net models, for all product codes // NB In practice you will probably want to set the prodcode_mask to the value of your product code ret_code = DinkeyChange.DCGetInfo(TYPE_MASK_ALL, MODEL_MASK_DEFAULT, null, MAX_USB_DEVICES, out num_found, type, model, prodcode, dongle_number, update_number); // check error code and display error if an error occurs if (ret_code == 401) { MessageBox.Show("No dongles detected matching the search criteria specified", AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else if (ret_code != 0) { DisplayString = "An error occurred getting dongle information. Error: " + String.Format("{0:D}", ret_code); MessageBox.Show(DisplayString, AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // display info for dongle(s) detected for (i=0; i