Thread: Reading A Byte From A Certain Offset

  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 05: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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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, 06:41 PM
  3. Replies: 3
    Last Post: 01-23-2006, 07: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, 08:44 AM