[fpc-pascal]reading windows registry

Charl van Jaarsveldt charlvj at ict.om.org
Mon Feb 2 13:52:49 CET 2004


Hallo.

I have this little program to get te info of a certain ODBC entry n the 
registry, but it doesn't work and I am at a loss. I admit, I haven't 
done too much win32 stuff before. Any ideas and help would be appreciated.

Peace.
Charl


Here is the program: (please see comments at the end)

Program RegTest01;

Uses
  Crt, windows;
 
Var
  key : HKEY;
  pt : array[0..80] of char;
  bl, ret : DWORD;
  s : string;

Begin
  If paramCount <> 1 Then
  Begin
    writeln( 'Usage:' );
    writeln( '   ', paramstr( 0 ), ' <datasource name>' );
    halt( 0 );
  End;
  s := paramStr( 1 );
  RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                'Software\ODBC\ODBC.INI\ODBC Data Sources',
                0, KEY_QUERY_VALUE, key );
  ret := RegQueryValueEx( key, @s[1], nil, nil, @pt, @bl );
  RegCloseKey( key );

  {Now, when the datasource is valid, bl = 0 and ret = 2  - not sure 
what the return value 2 means :-(
    If the datasource IS valid, I get bl = size of the value (correctly) 
pt = '', and ret = 234 (ERROR_MORE_DATA)
    I have tried with really BIG buffers and I get the same result}

  writeln( 'pt = ', pt, '     bl = ', bl );
  writeln( 'return: ', ret );
End.





More information about the fpc-pascal mailing list