?? form1.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using VDSDKLib;
namespace Sharp
{
public class CVirtualDriveHandler : VDSDKLib.IVirtualDriveHandler2
{
private byte[] m_buffer;
public CVirtualDriveHandler(uint diskSize)
{
m_buffer = new byte[diskSize*1024*1024];
}
~CVirtualDriveHandler()
{
m_buffer = null;
}
public uint OnReadData(System.UInt64 Offset, uint Size,out System.Array Buffer)
{
byte[] buf = new byte[Size];
System.Array.Copy(m_buffer,(int)Offset,buf,0,(int)Size);
Buffer = buf;
return Size;
}
public uint OnWriteData(System.UInt64 Offset, uint Size,ref System.Array Buffer)
{
System.Array.Copy((byte[])Buffer,0,m_buffer,(int)Offset, (int)Size);
return Size;
}
}
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
CreateBtn.Enabled = true;
DestroyBtn.Enabled = false;
m_driveHandle = -1;
m_pHandler = null;
// initialize VDSDK
m_pManager = new VDSDKLib.VirtualDrivesManagerClass();
m_pManager.InitializeVDSDK();
}
~Form1()
{
// shutdown VDSDK
m_pManager.ShutdownVDSDK(1);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.CreateBtn = new System.Windows.Forms.Button();
this.DestroyBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// CreateBtn
//
this.CreateBtn.Location = new System.Drawing.Point(40, 160);
this.CreateBtn.Name = "CreateBtn";
this.CreateBtn.TabIndex = 0;
this.CreateBtn.Text = "Create";
this.CreateBtn.Click += new System.EventHandler(this.CreateBtn_click);
//
// DestroyBtn
//
this.DestroyBtn.Location = new System.Drawing.Point(136, 160);
this.DestroyBtn.Name = "DestroyBtn";
this.DestroyBtn.TabIndex = 0;
this.DestroyBtn.Text = "Destroy";
this.DestroyBtn.Click += new System.EventHandler(this.DestroyBtn_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.CreateBtn);
this.Controls.Add(this.DestroyBtn);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private System.Windows.Forms.Button CreateBtn;
private System.Windows.Forms.Button DestroyBtn;
// internal variables
private CVirtualDriveHandler m_pHandler; // out virtual drive event handler
private int m_driveHandle; // virtual drive handle
private VDSDKLib.VirtualDrivesManagerClass m_pManager; // VDSDK manager
private void CreateBtn_click(object sender, System.EventArgs e)
{
m_pHandler = new CVirtualDriveHandler(16);
m_driveHandle = m_pManager.CreateVirtualDrive((byte)'Z',16,m_pHandler);
if(m_driveHandle != -1)
{
CreateBtn.Enabled = false;
DestroyBtn.Enabled = true;
}
else
{
m_pHandler = null;
}
}
private void DestroyBtn_Click(object sender, System.EventArgs e)
{
if(m_driveHandle != -1)
{
m_pManager.DestroyVirtualDrive(m_driveHandle,1);
m_pHandler = null;
m_driveHandle = -1;
CreateBtn.Enabled = true;
DestroyBtn.Enabled = false;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -