求助,请问c#里面如何调用CreateFile

解决方案 »

  1.   

    [DllImport("kernel32.dll", CharSet = CharSet.Auto,  
        CallingConvention = CallingConvention.StdCall,  
        SetLastError = true)] 
    public static extern SafeFileHandle CreateFile( 
        string lpFileName, 
        uint dwDesiredAccess, 
        uint dwShareMode, 
        IntPtr SecurityAttributes, 
        uint dwCreationDisposition, 
        uint dwFlagsAndAttributes, 
        IntPtr hTemplateFile 
    ); 
      

  2.   

    HANDLE CreateFile(LPCTSTR lpFileName,
    DWORD dwDesiredAccess,
    DWORD dwShareMode,
    LPSECURITY_ATTRIBUTES lpSecurityAttributes
    DWORD dwCreationDisposition
    DWORD dwFlagsAndAttributes
    HANDLE hTemplateFile);
    创建一个指定类列的文件
    handleValue = CreateFile(@""+driverName , GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);  
      

  3.   

       System.IO.File.Create("d:\\1.txt").Close();
      

  4.   

                string COMString = "COM1";
                int hComm = CreateFile(COMString, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
      

  5.   

            [DllImport("kernel32.dll")]
            private static extern int CreateFile(
             string lpFileName,                         // file name
             uint dwDesiredAccess,                      // access mode
             int dwShareMode,                           // share mode
             int lpSecurityAttributes,                  // SD
             int dwCreationDisposition,                 // how to create
             int dwFlagsAndAttributes,                  // file attributes
             int hTemplateFile                          // handle to template file
             );
      

  6.   


    LS这个回复,真TMD臭屁…… 莫装B,装B遭雷劈……砖家……
      

  7.   


    不明白CSDN为什么会走出你这这样的人!不会就说不会,别在那里就会装,你知道这个有什么用吗?连最基本都没有搞懂就别乱说话,只会添乱!