|
-
December 18th, 2007, 03:09 PM
#1
problem with unicode and files
I'm trying to read data from file into a Unicode string, and even though that according to dwRead ,
it does read bytes from the file, the szUnicode string is still empty.
here is the code:
Code:
wchar_t *getFile(char *fname)
{
HANDLE hFile=CreateFile(fname,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
NULL,
NULL);
int num;
wchar_t *szUnicode;
DWORD dwRead;
if(hFile==INVALID_HANDLE_VALUE)
return NULL;
num=GetFileSize(hFile,NULL);
szUnicode=(wchar_t*)malloc(sizeof(wchar_t) * num);
ReadFile(hFile,(LPVOID)szUnicode,num,&dwRead,NULL);
wprintf(szUnicode);
CloseHandle(hFile);
return szUnicode;
}
anyone has any idea?
thanks in advance.
-
December 18th, 2007, 04:23 PM
#2
Re: problem with unicode and files
(Make sure ReadFile returns TRUE)
So what does szUnicode contain?
Did you write the sting to the file yourself (from your program)? If the file/content was created with an editor, you should make you saved the file without BOM bytes.
-
December 18th, 2007, 07:15 PM
#3
Re: problem with unicode and files
yeah, that was the problem, thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|