天下

记录修行的印记

文件的HANDLE转化为FILE*

#include <iostream>
#include 
<fcntl.h>
#include 
<io.h>
#include 
<afxwin.h>
using namespace std;

void Test() { 
    HANDLE   hFile   
=   CreateFile( "c:\\test.dat "
        GENERIC_READ   
|   GENERIC_WRITE,   0,   NULL,   
        OPEN_ALWAYS,   FILE_ATTRIBUTE_NORMAL,   NULL); 

    
char   szText[]   =   "Hello   world!\n "
    DWORD   dwWritten; 
    WriteFile(hFile,   szText,   strlen(szText),   
&dwWritten,   NULL); 

    FILE
*   pFile   =   NULL; 
    
int   nHandle   =   _open_osfhandle((long)hFile, _O_TEXT|_O_APPEND); 
    
if   (nHandle   !=   -1) {
        pFile   
=   _fdopen(nHandle,   "wt "); 
    }

    
if(pFile) { 
        
int   n   =   fputs( "write   by   FILE*! ",   pFile);
        fflush(pFile);
//立即写入文件
    } 
    CloseHandle(hFile); 
}

int main()
{
    Test();
    
return 0;
}

posted on 2010-12-25 15:19 天下 阅读(382) 评论(0)  编辑 收藏 引用 所属分类: Win32


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年12月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论