Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
library testdll; uses sysutils, registry, windows;
// written by Glenn9999 at tek-tips.com. Demo illustrating how to pass string
// or record data from a DLL to a main program WITHOUT using ShareMem.
function GetWallPaperPath(wallpaper: PChar; var buflen: Word): Bool; stdcall;
{ gets the desktop wallpaper as currently set for the current user.
receives: Wallpaper as pointer to data buffer, buflen as the length of the
buffer provided to the DLL. Returns the data at the address supplied in
"wallpaper", and the actual length of the data in "buflen" }
var
regobj: TRegistry;
wpresult: string;
begin
Result := false;
regobj := TRegistry.Create;
try
regobj.rootkey := HKEY_CURRENT_USER;
if regobj.OpenKey('Control Panel\Desktop', false) then
begin
wpresult := regobj.ReadString('Wallpaper');
// You can't use wpresult as a direct basis for data return since it
// resides in an address that is not valid to the calling application.
// so you copy it to a supplied PChar which represents a buffer of
// sufficient size.
StrPCopy(wallpaper, wpresult);
// pass the real length of the data in buffer.
buflen := Length(wpresult);
Result := true;
end
finally
regobj.CloseKey;
regobj.free;
end;
end;
exports
GetWallPaperPath;
begin
end.
{$APPTYPE CONSOLE}
program testmain; uses sysutils;
// main program written by Glenn9999 at tek-tips.com. Illustrates calling the
// DLL function provided as a sample.
function GetWallPaperPath(wallpaper: PChar; var buflen: Word): Bool;
stdcall; external 'testdll.dll';
var
Teststring: string;
teststringlen: Word;
begin
{ this is how I usually call Windows API functions which involve string data.
While there may be an easier way which is compatible, this seems the easiest
that I know. You can change the size of a string, point to the string and
then change it back to the actual length of the returned data. }
teststringlen := 255;
SetLength(teststring, teststringlen);
GetWallPaperPath(PChar(teststring), teststringlen);
SetLength(teststring, teststringlen);
{ writing * here so the length of the string can be easily spotted. Returning
a string that is complete and of the right length is perhaps the more difficult thing in calling "compatible" DLL functions which return string data.}
writeln('WallPaper path for current user is: ', teststring, '*');
readln;
end.