在WIN编程下,我要创建一个文件,想要CREATEFILE这个函数,但试了之后有问题,求给个例子。

解决方案 »

  1.   

    HANDLE hFile = CreateFile( _T(".\\clntgrp.dat"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
      

  2.   

    #include <windows.h>
    #include <stdio.h>HANDLE hFile; 
     
    hFile = CreateFile(TEXT("myfile.txt"),    // file to open
                       GENERIC_READ,          // open for reading
                       FILE_SHARE_READ,       // share for reading
                       NULL,                  // default security
                       OPEN_EXISTING,         // existing file only
                       FILE_ATTRIBUTE_NORMAL, // normal file
                       NULL);                 // no attr. template
     
    if (hFile == INVALID_HANDLE_VALUE) 

        printf("Could not open file (error %d)\n", GetLastError());
        return 0;
    }
      

  3.   

    (".\\clntgrp.dat"), 关键是用\\来代替\
      

  4.   

    关于路径楼上的几位讲得很清楚了还有,你说你要创建一个新文件出错,我估计是不是你使用第五个参数的时候使用不当呢,呵呵CREATE_ALWAYS 
    Creates a new file. If the file exists, the function overwrites the file and clears the existing attributes. 用这个参数就可以反复创建了
      

  5.   

    谢谢各位了,我少了一个TEXT宏,直接就“路径”了!呵呵