Reading A Byte From A Certain Offset

This is a discussion on Reading A Byte From A Certain Offset within the Windows Programming forums, part of the Platform Specific Boards category; I need to open a file, read a certain byte from that file, and display that number in the list ...

  1. #1
    Registered User 4point5's Avatar
    Join Date
    Oct 2002
    Posts
    44

    Question Reading A Byte From A Certain Offset

    I need to open a file, read a certain byte from that file, and display that number in the list box. For some reason, I can't get it to work. Here is my code.
    Code:
    BOOL GetZSTFileName(HWND hWnd)
    {
    	OPENFILENAME ofn;
    	OVERLAPPED ovl;
    	CHAR szFileName[MAX_PATH];
    	HANDLE hFile;
    	BYTE bBuffer;
    
        ZeroMemory(&ofn, sizeof(OPENFILENAME));
    	ofn.lStructSize = sizeof(OPENFILENAME);
    	ofn.hwndOwner   = hWnd;
    	ofn.lpstrFilter = "ZSNES Save State Files (*.zs*)\0*.zs*\0\0";
    	ofn.lpstrFile   = szFileName;
    	ofn.nMaxFile    = MAX_PATH;
    	ofn.Flags       = OFN_FILEMUSTEXIST;
    
    	ZeroMemory(&ovl, sizeof(OVERLAPPED));
    	ovl.Offset     = 0x3013;
    	ovl.OffsetHigh = 0x0000;
    
    	GetOpenFileName(&ofn);
    	hFile = CreateFile(szFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 
    		               FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
    	ReadFile(hFile, &bBuffer, 1, NULL, &ovl);
    	SendDlgItemMessage(hWnd, IDC_ITEMS, LB_ADDSTRING, NULL, (LPARAM)bBuffer);
    
    	return 0;
    }
    Any help at all would be appreciated. Thanks.
    Last edited by 4point5; 10-31-2002 at 04:58 PM.
    Don't try so hard. Just let it happen.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Wow. All that work for just one byte? Heh. Well tell me, are you not getting the data or just not able to get it to the control? Anyway, it looks like you're sending the byte as is to it, probably showing nothing. Look at this:

    char buff[10];
    char val = 26;
    sprintf(buff, "%i", val);
    printf("%s", buff);

    See?
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My memory management solution
    By cboard_member in forum Game Programming
    Replies: 20
    Last Post: 08-23-2006, 09:07 AM
  2. Fun with reading hex
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 02-17-2006, 05:41 PM
  3. Replies: 3
    Last Post: 01-23-2006, 06:25 PM
  4. Relocation in .obj -files
    By willkoh in forum C++ Programming
    Replies: 6
    Last Post: 04-06-2005, 01:59 PM
  5. arrays and structs
    By westclok in forum C Programming
    Replies: 11
    Last Post: 02-25-2005, 07:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21