Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have to read a unicode file using Readfile api of MSDNhttp://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx[^].

C++
char*	pBuf = NULL;
....
pBuf = (char*)new char[ dwFileSize+1 ];
bResult = ::ReadFile( hFile, pBuf, dwFileSize, &br, NULL );


But it is coming garbage value in pBuf?

Any Idea how to solve this. Above code fine for Multibyte files...

NOTE: Please comment / ans if you know solution.
Posted
Comments
iDebD 1-Mar-13 8:51am    
SOme info:

If I take wchar_t to allocate pBuf, then it can raed unicode file properly, but cannot read Multibyte ones..

You should properly interpret the file content. Richard's trip might be helpful: Handling simple text files in C/C++[^].
 
Share this answer
 
Comments
Richard MacCutchan 1-Mar-13 9:20am    
:thumbsup:
ReadFile as far as i know is not concerned about unicode, it just reads some amount of data from stream and returns to you. So now you need to interpret them.
there are apis to convert to unicode and back. (like MultiByteToWildChar and Wildchar..ToByte)

jkchan
[removed link to personal site]
 
Share this answer
 
v2
Comments
Mohibur Rashid 1-Mar-13 18:41pm    
why someone would remove link of personal site?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900