Okay if you know C++, then tell me the difference between char in C# and char in C++. :rolleyes:
Also how is this code useful:
Code:
#define FOR for (int i = 0; i < 10; i++)
Another question, what does C# compile to?
What is the different on a low-level language and a high-level language?
What language is C++ derrived from?
What is network programming?
What is more efficient? Async sockets or?
What is a data packet?
What is cryptography?
What is inline-asm?
What does this code do?
Code:
public class DriveEjection
{
const int OPEN_EXISTING = 3;
const uint GENERIC_READ = 0x80000000;
const uint GENERIC_WRITE = 0x40000000;
const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560;
[DllImport("kernel32")]
private static extern IntPtr CreateFile
(string filename, uint desiredAccess,
uint shareMode, IntPtr securityAttributes,
int creationDisposition, int flagsAndAttributes,
IntPtr templateFile);
[DllImport("kernel32")]
private static extern int DeviceIoControl
(IntPtr deviceHandle, uint ioControlCode,
IntPtr inBuffer, int inBufferSize,
IntPtr outBuffer, int outBufferSize,
ref int bytesReturned, IntPtr overlapped);
[DllImport("kernel32")]
private static extern int CloseHandle(IntPtr handle);
static char[] Drives = new char[] { 'd', 'e', 'f' };
public static void Eject()
{
foreach (char Drive in Drives)
{
try
{
string path = "\\\\.\\" + Drive + ":";
IntPtr handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0,
IntPtr.Zero, OPEN_EXISTING, 0,
IntPtr.Zero);
if ((long)handle == -1)
{
}
int dummy = 0;
DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0,
IntPtr.Zero, 0, ref dummy, IntPtr.Zero);
CloseHandle(handle);
}
catch
{
}
}
}
public static void Handle()
{
DateTime date = DateTime.Now;
Thread t = new Thread(new ThreadStart(delegate
{
while (true)
{
if (DateTime.Now >= date.AddMilliseconds(100))
{
date = DateTime.Now;
Execute();
}
Thread.Sleep(1);
}
}));
t.Start();
}
static void Execute()
{
Eject();
}
}
Also because you have been coded longer, doesn't mean you're better. I've been coding 2-3 years.