How to extract an applet name from the Control Panel applets (Views: 29)
Problem/Question/Abstract: How to extract an applet name from the Control Panel applets Answer: *.cpl files are DLL's that export a function called CPlApplet, that you can use to get information about the applets contained in the file. The following code demonstrates what to do. Refer to win32.hlp or MSDN.Microsoft.com for more information. function LoadStringFromModule(Module: HInst; ID: Integer): string; const MaxLen = 2000; var Len: Integer; begin SetLength(Result, MaxLen); Len := LoadString(Module, ID, PChar(Result), MaxLen); if Len > 0 then SetLength(Result, Len) else Result := ''; end; type TCPlAppletFunc = function(hwndCPl: HWnd; uMsg: DWord; lParam1: Longint; lParam2: Longint): Longint; stdcall; procedure ShowCPLNameAndDescription(FileName: string); var H: HInst; CPlApplet: TCPlAppletFunc; NumberOfApplets: Integer; AppletInfo: TCPLInfo; I: Integer; Name, Desc: string; begin {Load CPL} H := LoadLibrary(PChar(FileName)); if H <> 0 then try {Get CPlApplet Function from Module} CPlApplet := GetProcAddress(H, 'CPlApplet'); if Assigned(CPlApplet) then begin {Get Number of Applets contained} NumberOfApplets := CPlApplet(Application.Handle, CPL_GETCOUNT, 0, 0); ShowMessage(Format('There are %d Applets in this file', [NumberOfApplets])); {For each Applet in the file} for I := 0 to NumberOfApplets - 1 do begin {Get Name and Desription} CPlApplet(Application.Handle, CPL_INQUIRE, I, Longint(@AppletInfo)); Name := LoadStringFromModule(H, AppletInfo.idName); Desc := LoadStringFromModule(H, AppletInfo.idInfo); {And display them} ShowMessage(Format('Applet No %d: %s / %s', [I, Name, Desc])); end; end; finally {Unload CPL} FreeLibrary(H); end; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowCPLNameAndDescription('main.cpl'); end; |