Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Win32
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[^].
 
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 1-Mar-13 3:45am
iDebD842
Comments
bubaidada at 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..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should properly interpret the file content. Richard's trip might be helpful: Handling simple text files in C/C++[^].
  Permalink  
Comments
Richard MacCutchan at 1-Mar-13 9:20am
   
:thumbsup:
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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]
  Permalink  
v2
Comments
Mohibur Rashid at 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)

  Print Answers RSS
0 OriginalGriff 645
1 Maciej Los 225
2 Abhinav S 171
3 Richard Deeming 160
4 Suvendu Shekhar Giri 159
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,135
2 Peter Leow 5,042
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581


Advertise | Privacy | Mobile
Web02 | 2.8.150327.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100