Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

Delphi v1. win95 ini/registry access how to?

I am trying to obtain the name of the current domain server PDC from either the Windows 95 registry (I think I know where it is stored(?)) using Delphi v1. Should this not be possible, is there another way of obtaining this info during runtime - possibly from ini files if Delphi 1 can't read the registry. If this is the case, which ini file(S) do I search. Thanks in advance for any help anyone is able to offer. The idea is that the resulting programme will be required to run in different domain environments and will therefore need to dynamically locate the server name.
0
rigsby
Asked:
rigsby
  • 2
1 Solution
 
d003303Commented:
Yo,
you could use generic thunks to read the registry. Generic thunking allows you to call a 32bit function fromout a 16bit application. There is a delphi unit on the net called call32.pas which provides generic thunking for Delphi 1. Get it at

http://sunsite.icm.edu.pl/delphi/ftp/freeware/call32nt.zip

and the helpfile at

http://sunsite.icm.edu.pl/delphi/ftp/docs/call32nt.zip

Then declare the function prototypes as
type
  PDWORD = ^LongInt;

var

  RegCloseKey32: function(hKey: HKEY): Longint;

  RegQueryValueEx: function(hKey: LongInt; lpValueName: PChar;
  lpReserved: Pointer; lpType: PDWORD; lpData: PByte; lpcbData: PDWORD; id: LongInt): Longint;

  RegOpenKeyEx: function(hKey: LongInt; lpSubKey: PChar;
  ulOptions: LongInt; samDesired: LongInt; var phkResult: LongInt; id: LongInt): Longint;

  id_RegCloseKey32,
  id_RegQueryValueEx,
  id_RegOpenKeyEx     : LongInt;

bind to the functions with

begin
  id_RegCloseKey32 := Declare32('id_RegCloseKey32', 'advapi32.dll', 'i');
  id_RegQueryValueEx := Declare32('RegQueryValueEx', 'advapi32.dll', 'ippppp');
  id_RegOpenKeyEx := Declare32('RegOpenKeyEx', 'advapi32.dll', 'ipiip');
end;

and use the functions like

begin
  aResult := id_RegCloseKey32(aKey, id_RegCloseKey32);
  aResult := RegOpenKeyEx(aKey, aSubKey, aOption, aSAM, aResult, id_RegOpenKeyEx);
  aResult := RegQueryValueEx(aKey, aName, Reserved, aType, aData, aDataLength, id_RegQueryValueEx);
end;


Slash/d003303
0
 
d003303Commented:
oops, some typos and one thing I forgot :
the line

aResult := id_RegCloseKey32(aKey, id_RegCloseKey32);

should read

aResult := RegCloseKey32(aKey, id_RegCloseKey32);

and the binding code misses the lines

  @RegCloseKey32 := @Call32;
  @RegOpenKeyEx := @Call32;
  @RegQueryValueEx := @Call32;

Slash/d003303
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now