本文介绍了MapViewOfFile和unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个文件映射并修改我的文件,但是当我修改我的文件时,却不是我想要的,我的英语很差,您可以看到此代码
我的项目是unicode
i want create a filemapping and modify my file,but when i modify my file ,but it not what i want,my english is very poor ,you can see this code
my project is unicode
<br />
hfile=::CreateFile(TEXT("c:\\1.txt"),GENERIC_ALL|FILE_ALL_ACCESS,FILE_SHARE_WRITE|\<br />
FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);<br />
HANDLE hmap=::CreateFileMapping(hfile,NULL,PAGE_READWRITE,0,0,NULL);<br />
TCHAR*pmap=(TCHAR*)::MapViewOfFile(hmap,FILE_MAP_ALL_ACCESS,0,0,NULL);<br />
TCHAR*tmp=pmap;<br />
lstrcpy(tmp,TEXT("my test"));<br />
::UnmapViewOfFile(pmap);<br />
::CloseHandle(hmap);<br />
::CloseHandle(hfile);<br />
c:\ 1.txt为我的测试",我希望它为我的测试"
我该如何实现这个
c:\1.txt is "m y t e s t" ,i want it is "my test"
how do i achieve this
推荐答案
hfile = ::CreateFile(
TEXT("c:\\1.txt"),
GENERIC_ALL | FILE_ALL_ACCESS,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
HANDLE hmap = ::CreateFileMapping(
hfile,
NULL,
PAGE_READWRITE,
0,
0,
NULL);
TCHAR *pmap = (TCHAR*)::MapViewOfFile(
hmap,
FILE_MAP_ALL_ACCESS,
0,
0,
NULL);
*pmap = (TCHAR)0xFEFF;
TCHAR *tmp = pmap + 1;
lstrcpy(tmp, TEXT("my test"));
::UnmapViewOfFile(pmap);
::CloseHandle(hmap);
::CloseHandle(hfile);
有关 BOM 的更多信息,请单击以下链接: http://www. websina.com/bugzero/kb/unicode-bom.html [ ^ ]
For more informations about BOM you can follow this link: http://www.websina.com/bugzero/kb/unicode-bom.html[^]
这篇关于MapViewOfFile和unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!