Question: I'm want write name of my pc to a txt file using `SysUtils.FileWrite` api, in my last attempt is wrote with sucess, but the trouble is that visually is cutting some characters, but size of text inside file have exactly the same size as if string is complete visually.

Eg: My pc is called of "TESTE-PC" (Without double quotes). The string "TESTE-PC" (Without double quotes) have exactly 8 bits, but `SysUtils.FileWrite` writes only "TEST" and size of file after is 8 bits. Very strange! :(

Thank you for any suggestion.

```
uses
 Registry;

...

function GetCompName: string;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.rootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName', false) then
    begin
      Result := Reg.ReadString('ComputerName');
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
 hFile: THandle;
 Str: PWideChar;
begin

if not fileexists('test.txt') then
begin
  Str := PWideChar(GetCompName);
  hFile:=  CreateFile('test.txt', GENERIC_WRITE, 0, nil, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0);
  FileWrite(hFile, Str^, Length(Str));
  CloseHandle(hFile);
end;

end;

```

Answer: 
If you need to write **wide** chars, take their size into account: 

```
FileWrite(hFile, Str^, Length(Str) * SizeOf(Char));

```
Change the type of `str` to `RawByteString` instead of `PWideChar`

```
procedure TForm1.FormCreate(Sender: TObject);
var
   hFile:  THandle;
   sFileName: string;
   Str: RawByteString;
begin
     Str := PWideChar(GetCompName);
     sFileName := 'Test.txt';
    if fileExists(sFileName) then
      hFile := fileOpen(sFileName,fmOpenReadWrite)
    else
      hFile := fileCreate(sFileName);
     try
       FileWrite(hFile,
        PChar(Str)^, Length(Str));
     finally
       FileClose(hFile);
     end;
end;

```