[DUG] Reading binary data as date/time from registry

Edward Koryagin ed_iv2001 at yahoo.co.nz
Thu May 13 17:22:31 NZST 2010


procedure TRegistry.WriteDateTime(const Name: string; Value: TDateTime);
begin
  PutData(Name, @Value, SizeOf(TDateTime), rdBinary);
end;

function RegDataToDataType(Value: TRegDataType): Integer;
begin
  case Value of
    rdString: Result := REG_SZ;
    rdExpandString: Result := REG_EXPAND_SZ;
    rdInteger: Result := REG_DWORD;
    rdBinary: Result := REG_BINARY;
  else
    Result := REG_NONE;
  end;
end;


procedure TRegistry.PutData(const Name: string; Buffer: Pointer;
  BufSize: Integer; RegData: TRegDataType);
var
  DataType: Integer;
begin
  DataType := RegDataToDataType(RegData);
  if RegSetValueEx(CurrentKey, PChar(Name), 0, DataType, Buffer,
    BufSize) <> ERROR_SUCCESS then
    raise ERegistryException.CreateResFmt(@SRegSetDataFailed, [Name]);
end;

Edward Koryagin


--- On Thu, 13/5/10, Jan Bakuwel <jan.bakuwel at omiha.com> wrote:

> From: Jan Bakuwel <jan.bakuwel at omiha.com>
> Subject: [DUG] Reading binary data as date/time from registry
> To: "'NZ Borland Developers Group - Delphi List'" <delphi at delphi.org.nz>
> Received: Thursday, 13 May, 2010, 1:22 PM
> Hi,
> 
> I'm struggling to find a good reference how I can read a
> date/time that
> is stored in the registry. Its stored in the registry by a
> Microsoft
> product; I'd like to read it with Delphi.
> 
> Here are some examples:
> 
> DateLastChecked     REG_BINARY 
>   95 a2 58 f2 2d f2 ca 01
> 
> When I write dates with Delphi
> (TRegistry.WriteDateTime(Now()), I get
> the following results:
> 
> 13 may 2010 12:56pm        03 ce dc 3f
> f1 ae e3 40
> 13 may 2010 12:57pm        39 75 33 48
> f1 ae e3 40
> 13 may 2010 1:01pm          3e 47
> d1 60 f1 ae e3 40
> 
> The last 4 bytes seem to resemble the date, the first the
> time.
> 
> When I use TRegistry.ReadDateTime on those entries, I get
> 30/12/1899.
> 
> Suggestions are very welcome!
> 
> thanks,
> Jan
> 
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz
> with Subject: unsubscribe
> 


      




More information about the Delphi mailing list