using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("jydisk.dll")]
        static extern int GetDiskType1(byte msg);
        [DllImport("jydisk.dll")]
        static extern int GetDiskIndex(byte msg);
        [DllImport("jydisk.dll")]
        static extern void GetDiskSerialNumber1(byte msg, StringBuilder sn, out  int len);
        [DllImport("jydisk.dll")]
        static extern void DoReg(StringBuilder fuser, int usersize, StringBuilder fregid, int regidsize);
        [DllImport("jydisk.dll")]
        static extern void GetDiskSerialNumber2(int msg, StringBuilder sn, out  int len);
        [DllImport("jydisk.dll")]
        static extern void GetDiskDrive(int PhysicalDriveId, StringBuilder pout, out  int len);
        [DllImport("jydisk.dll")]
        static extern void GetPhysicalDriveCount(StringBuilder pout, out  int len);
        [DllImport("jydisk.dll")]
        static extern bool RunAsAdmin();
        [DllImport("jydisk.dll")]
        static extern bool IsRegisted();
        
        public Form1()
        {
            InitializeComponent();
        }
         
        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(textBox1.Text);
            int i = GetDiskType1(System.Convert.ToByte(textBox1.Text[0]));
            string s ="硬盘";
            if (i == 1) //then
                s = "移动硬盘";
            if (i == 2) //then
                s = "优盘";
            Text = s;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int i = GetDiskIndex(System.Convert.ToByte(textBox1.Text[0]));
            string s = Convert.ToString(i);
            Text = s;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            StringBuilder s=new StringBuilder(100) ;
            int len=0;
            GetDiskSerialNumber1(System.Convert.ToByte(textBox1.Text[0]), s, out len);
            string ss = s.ToString(0,len);
            Text = ss;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            StringBuilder userid = new StringBuilder(textBox2.Text);
            StringBuilder regid = new StringBuilder(textBox3.Text);
            int usersize = textBox2.TextLength;
            int regidsize = textBox3.TextLength;
            DoReg(userid, usersize, regid, regidsize);
        }

        private void button5_Click(object sender, EventArgs e)
        {
        if (IsRegisted()==true)
        {Text="ok";}
        else
        {Text="no";}
        }
    }
}
