Author: Tomas Rutkauskas
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.
1
2 function LoadStringFromModule(Module: HInst; ID: Integer): string;
3 const
4 MaxLen = 2000;
5 var
6 Len: Integer;
7 begin
8 SetLength(Result, MaxLen);
9 Len := LoadString(Module, ID, PChar(Result), MaxLen);
10 if Len > 0 then
11 SetLength(Result, Len)
12 else
13 Result := '';
14 end;
15
16 type
17 TCPlAppletFunc = function(hwndCPl: HWnd; uMsg: DWord; lParam1: Longint;
18 lParam2: Longint): Longint; stdcall;
19
20 procedure ShowCPLNameAndDescription(FileName: string);
21 var
22 H: HInst;
23 CPlApplet: TCPlAppletFunc;
24 NumberOfApplets: Integer;
25 AppletInfo: TCPLInfo;
26 I: Integer;
27 Name, Desc: string;
28 begin
29 {Load CPL}
30 H := LoadLibrary(PChar(FileName));
31 if H <> 0 then
32 try
33 {Get CPlApplet Function from Module}
34 CPlApplet := GetProcAddress(H, 'CPlApplet');
35 if Assigned(CPlApplet) then
36 begin
37 {Get Number of Applets contained}
38 NumberOfApplets := CPlApplet(Application.Handle, CPL_GETCOUNT, 0, 0);
39 ShowMessage(Format('There are %d Applets in this file', [NumberOfApplets]));
40 {For each Applet in the file}
41 for I := 0 to NumberOfApplets - 1 do
42 begin
43 {Get Name and Desription}
44 CPlApplet(Application.Handle, CPL_INQUIRE, I, Longint(@AppletInfo));
45 Name := LoadStringFromModule(H, AppletInfo.idName);
46 Desc := LoadStringFromModule(H, AppletInfo.idInfo);
47 {And display them}
48 ShowMessage(Format('Applet No %d: %s / %s', [I, Name, Desc]));
49 end;
50 end;
51 finally
52 {Unload CPL}
53 FreeLibrary(H);
54 end;
55 end;
56
57 procedure TForm1.Button1Click(Sender: TObject);
58 begin
59 ShowCPLNameAndDescription('main.cpl');
60 end;
|