下面是示例在C#里面调用win32api中的 CreateFile 和 CloseHandle 这两个函数。
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace copytest
{
/// <summary>
/// FileAccess 的摘要说明。
/// </summary>
public class OpenFileApi
{
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const int CREATE_NEW = 1;
private const int CREATE_ALWAYS = 2;
private const int OPEN_EXISTING = 3;
private const int OPEN_ALWAYS = 4;
private const int FILE_SHARE_READ = 0x1;
private const int FILE_SHARE_WRITE = 0x2;
private const uint FILE_ATTRIBUTE_READONLY = 0x1;
private const uint FILE_ATTRIBUTE_HIDDEN = 0x2;
private const uint FILE_ATTRIBUTE_SYSTEM = 0x4;
private const uint FILE_ATTRIBUTE_DIRECTORY = 0x10;
private const ui