Click here to Skip to main content
15,889,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: adding an item into control panel context menu Pin
«_Superman_»15-Jul-09 2:04
professional«_Superman_»15-Jul-09 2:04 
Questionunicode equivalent of Readfile() function.. Pin
Rakesh514-Jul-09 22:42
Rakesh514-Jul-09 22:42 
AnswerRe: unicode equivalent of Readfile() function.. Pin
Naveen14-Jul-09 22:55
Naveen14-Jul-09 22:55 
QuestionRe: unicode equivalent of Readfile() function.. Pin
Rajesh R Subramanian14-Jul-09 22:57
professionalRajesh R Subramanian14-Jul-09 22:57 
AnswerRe: unicode equivalent of Readfile() function.. Pin
Rakesh514-Jul-09 23:36
Rakesh514-Jul-09 23:36 
QuestionRe: unicode equivalent of Readfile() function.. [modified] Pin
Rajesh R Subramanian14-Jul-09 23:52
professionalRajesh R Subramanian14-Jul-09 23:52 
AnswerRe: unicode equivalent of Readfile() function.. Pin
CPallini14-Jul-09 23:09
mveCPallini14-Jul-09 23:09 
AnswerRe: unicode equivalent of Readfile() function.. Pin
Nishad S15-Jul-09 0:38
Nishad S15-Jul-09 0:38 
In short, using the ReadFile, will read the file content as bytes. Neither as unicode nor as MBCS, but simply as binary data. It is our concern whether it should be treated as unicode or not.

I am ignoring the inconsistency of the variables in your sample code. But still I found a mistake in your code.

That is you are allocating the buffer as 'new TCHAR[m_nBufferSize]'. It is wrong since the GetFileSize will return the exact size of the file in number of bytes. So when you are compiling with unicode enabled, the size of the TCHAR will be 2 (means sizeof unsigned short) and the buffer allocated will be twice of what we needed. Also it should be noted that the data read will not be directly converted to unicode (even if the buffer is of TCHAR).

And, from your question I understand that your file will be in unicode format. If this is true, then you can read it as follows. (modifications might be necessary)

int nSize = GetFileSize(...);
byte* pBytes = new byte[nSize];
ReadFile(..., pBytes, ...); // now the content of the file is in the buffer
MessageBox(.., LPCTSTR(pBytes), ... ); // you should make the buffer string null terminating if needed


This is the case when your file is in binary format.

When you save a file as unicode using notepad, you can see the first two bytes will be FF FE. So when you reading the file you can check that for ensuring the file is unicode and can ignore those bytes from using as data.

Suppose the content of a unicode file is 'abcd', then the binary equalent will be FF FE 61 00 62 00 63 00 64 00. You can see this when you open a file as binary in the VC editor itself.

I hope my explanation is clear for you.

(By the way, I am not sure about any APIs which will directly read a unicode file)

- ns ami -

Questionwhat is IWshRuntimeLibrary? Pin
V K 214-Jul-09 22:03
V K 214-Jul-09 22:03 
AnswerRe: what is IWshRuntimeLibrary? Pin
CPallini14-Jul-09 22:13
mveCPallini14-Jul-09 22:13 
Questiontoolbar controls Pin
Member 59031014-Jul-09 21:29
Member 59031014-Jul-09 21:29 
AnswerRe: toolbar controls Pin
_AnsHUMAN_ 14-Jul-09 21:38
_AnsHUMAN_ 14-Jul-09 21:38 
AnswerRe: toolbar controls Pin
Stuart Dootson14-Jul-09 21:45
professionalStuart Dootson14-Jul-09 21:45 
GeneralRe: toolbar controls Pin
Member 59031014-Jul-09 23:58
Member 59031014-Jul-09 23:58 
QuestionHow to read command line arguments in vc++ Pin
KASR114-Jul-09 21:11
KASR114-Jul-09 21:11 
AnswerRe: How to read command line arguments in vc++ Pin
_AnsHUMAN_ 14-Jul-09 21:31
_AnsHUMAN_ 14-Jul-09 21:31 
AnswerRe: How to read command line arguments in vc++ Pin
Rajesh R Subramanian14-Jul-09 21:32
professionalRajesh R Subramanian14-Jul-09 21:32 
AnswerRe: How to read command line arguments in vc++ Pin
CPallini14-Jul-09 21:39
mveCPallini14-Jul-09 21:39 
GeneralRe: How to read command line arguments in vc++ Pin
KASR114-Jul-09 22:24
KASR114-Jul-09 22:24 
AnswerRe: How to read command line arguments in vc++ Pin
Member 392263915-Jul-09 2:25
Member 392263915-Jul-09 2:25 
Questionhelp in modifying a code?[SOLVED] Pin
jon ray14-Jul-09 18:04
jon ray14-Jul-09 18:04 
AnswerRe: help in modifying a code? Pin
chandu00414-Jul-09 18:09
chandu00414-Jul-09 18:09 
AnswerRe: help in modifying a code? Pin
carter200014-Jul-09 18:28
carter200014-Jul-09 18:28 
GeneralRe: help in modifying a code? Pin
jon ray14-Jul-09 18:46
jon ray14-Jul-09 18:46 
GeneralRe: help in modifying a code? Pin
carter200014-Jul-09 18:59
carter200014-Jul-09 18:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.