新的应该用CreateFile了,OpenFile已经列为Obsolete了。

解决方案 »

  1.   

    1。OpenFile function is provided for compatibility with 16-bit versions of Windows!2。Win32-based applications should use the CreateFile function. 3。The SetFilePointer function moves the file pointer of an open file. 4。use WriteFile、ReadFile to Write/Read.
      

  2.   

    为何我用WriteFile只能望我用CreateFile建立的文件写一行信息?如何设置WriteFile为追加?
      

  3.   

    我知道你想作什么,呵呵,下面是代码,win32的,呵呵,给分吧
    HANDLE hFile;
    //初始文件句柄为空
    hFile=NULL;//创建文件句柄
    hFile=CreateFile("text.txt",GENERIC_WRITE|GENERIC_READ, FILE_SHARE_READ, NULL,
            OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if(hFile==NULL)
    {
            AfxMessageBox("创建文件句柄失败!");
    }//将文件指针指到文件末尾
    SetFilePointer(hFile,0,NULL,FILE_END);
    //将数据写入文件
    CString outputText;
    DWORD nLen;
    WriteFile(hFile,outputText,nLen, (ULONG *)&nLen, NULL);
      

  4.   

    为什么我写入的都是乱码?
    char buffer[]="Test for Visual C++"
    DOWORD nWrite;
    hFile=CreateFile((LPCSTR)"c:\\test.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    if(INVALID_HANDLE_VALUE!=hFile)
    {
    SetFilePointer(hFile,0,NULL,FILE_END);
    WriteFile(hFile,buffer,sizeof(buffer),&nWrite,NULL);
    }
    else
    MessageBox(NULL,"Open File Failed!","Failed:",MB_OK);
    break;
      

  5.   

    写入参数不对WriteFile()函数的参数好好看看
      

  6.   

    你用的是UNICODE模式吗,这样会出乱码。