Solved: Character Reading problem with ReadFile()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MattKent
    New Member
    • Nov 2007
    • 8

    Solved: Character Reading problem with ReadFile()

    I've figured it out. It was quite obvious really; use chars instead of DWORDS. Thanks for anyone who looked anyway.


    Hi,

    I've been having trouble with this for the past 48 hours. I hope someone can point me in the right direction. Basically I have a text file of characters. I want to read this into the program, but it's a Windows program so I'm using the open file dialogue.

    Everything goes fine; I gain a handle from the dialogue; I use read file and populate a buffer with the characters (in theory) and for testing purposes I output this value to a status bar on the program.

    Only I find that the buffer is populated with every fourth value from the string, e.g:

    2459674835137 stores in the buffer positions [0-3] as 2, 6, 3, 7.

    Here is the code in WinMain which takes the value and sends to status bar:
    Code:
    	wchar_t myword [2] = { 'H','\0' };	
    	DWORD temp = 0;
    	temp = DataM.OpenReadFile(hWnd, message, wParam, lParam);
    	myword[0] = (char)temp;
    	SendMessage((HWND) StatusBar,(UINT) SB_SETTEXT, (INT) 0, (LPARAM)myword);

    And this is function involved (DataM.OpenRead File):
    Code:
    	DWORD DataManager::OpenReadFile(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
    	HANDLE fileHndl = UIHandle.OpenFile(hWnd, message, wParam, lParam);
    	DWORD dwBuffer[256];
    	DWORD dwNumRead;
    	ReadFile(fileHndl, dwBuffer, sizeof(int)*256, &dwNumRead, NULL);
    	DWORD result;
    	
    	/*for(int i=0; i<256; i++){
    		if((wchar_t)dwBuffer[i] == '2'){
    			//result = (wchar_t)dwBuffer[i];
    			result = 'Z';
    			break;
    		}
    	}*/
    
    	result = dwBuffer[0];
    
    	return result;
      }
    So can anybody suggest why only 3 quarters of the characters are being extracted? Also what can be done to get around this?
    Any help whatsover would be extremely appreciated.

    Thank you very much in advance.
    Last edited by MattKent; Feb 26 '08, 03:04 PM. Reason: Suceeded!
Working...