CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    33

    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.

  2. #2
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    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.

  3. #3
    Join Date
    Dec 2007
    Posts
    33

    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
  •  





Click Here to Expand Forum to Full Width

Featured