All pastes #100650 Raw Edit

Miscellany

public text v1 · immutable
#100650 ·published 2006-07-26 09:36 UTC
rendered paste body
//------------------------------------------------------------------------------
procedure ReadFileIntoWBuffer(fname:String;Var buffer:PWideChar;Var size : Integer);
Var iFileHandle: Integer;
    iFileLength: Integer;
    iBytesRead: Integer;
    OutputLength: Integer;
    ws:WideString;
begin
  // read file into Buffer of pchar
  iFileHandle := FileOpen(fname, fmOpenRead);
  iFileLength := FileSeek(iFileHandle,0,2); //end of file
  FileSeek(iFileHandle,0,0); // start of file
  Buffer := PWideChar(AllocMem(iFileLength + 1));
  size:= iFileLength+1;
  FillChar(Buffer^,size,#0);
  iBytesRead := FileRead(iFileHandle, Buffer^, iFileLength);
  Assert(iBytesRead=iFileLength);
  FileClose(iFileHandle);
end;


main testing...

  ReadFileIntoWBuffer(testfolder+'ucode.org',buffer,size);
  if WideChar(buffer[0])=WideChar($FFFE)    // BOM_MSB_FIRST
  then ShowMessage('ok');


'ucode.org' in hexviewer first two bytes: $FFFE