Click here to Skip to main content
12,950,084 members (42,604 online)
Rate this:
 
Please Sign up or sign in to vote.
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[^].

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 2:45am
iDebD842
Comments
bubaidada 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 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 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
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2017
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