Results 1 to 3 of 3
  1. #1
    EmuTalk Member Mayco's Avatar
    Join Date
    Nov 2001
    Location
    Belgium
    Posts
    218

    the readfile function in delphi?

    I have a problem: when I use the readfile api function in delphi it returns everything what i need except the first byte (when the file begins with "123..." it just returns "23...").



    This is the piece of code I use:

    procedure openfile();
    var
    dwread:LongWord;
    hFile: THandle;
    data: Shortstring;
    begin
    hFile := createfile(PChar('c:\file.bin'), GENERIC_READ, FILE_SHARE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL + FILE_FLAG_RANDOM_ACCES, 0);
    SetFilePointer(hFile, 0, nil, FILE_BEGIN);
    Readfile(hFile, data, 64, dwread, nil);
    Closehandle(hFile);
    end;

    c:\file.bin is the file I want to read of course.
    data must contain the first 64 bytes of a binary file but it doesn't add the first byte.


    • Advertising

      advertising
      EmuTalk.net
      has no influence
      on the ads that
      are displayed
        
       

  2. #2
    Moderator Cyberman's Avatar
    Join Date
    Nov 2001
    Posts
    1,824

    Re: the readfile function in delphi?

    Originally posted by Mayco
    I have a problem: when I use the readfile api function in delphi it returns everything what i need except the first byte (when the file begins with "123..." it just returns "23...").

    This is the piece of code I use:

    procedure openfile();
    var
    dwread:LongWord;
    hFile: THandle;
    data: Shortstring;
    begin
    hFile := createfile(PChar('c:\file.bin'), GENERIC_READ, FILE_SHARE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL + FILE_FLAG_RANDOM_ACCES, 0);
    SetFilePointer(hFile, 0, nil, FILE_BEGIN);
    Readfile(hFile, data, 64, dwread, nil);
    Closehandle(hFile);
    end;

    c:\file.bin is the file I want to read of course.
    data must contain the first 64 bytes of a binary file but it doesn't add the first byte.
    I suggest not setting the file pointer the first time by commenting it out. Then run the code. Also if you have a 'file' position function I would dump that information to a debug text object in some window of your application. Useful for figuring out such things.

    Cyb
    Progress (n.):
    The process through which the Internet has evolved from smart people in front of dumb terminals to dumb people in front of smart terminals.
    -------------------------------------------------------------------
    Recursive (adj):
    see Recursive

  3. #3
    EmuTalk Member Mayco's Avatar
    Join Date
    Nov 2001
    Location
    Belgium
    Posts
    218
    ok, i have it:

    the data: Shortstring; must be data: array[1..64] of Char;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •