Solved

Control Panel Applet under NT

Posted on 1998-08-05
23
238 Views
Last Modified: 2010-04-04
I have to create an icon in the Control Panel from Windows NT. I use a DLL (renamed into a CPL) and the function CPLApplet. I guess there is someting wrong. Here is the code that does not work:

BOF---------------------------------------------
library pCPLApplet;

uses
  Forms,
  uCPLApplet in 'uCPLApplet.pas' {Form1},
  WinTypes, WinProcs, cpl, SysUtils;

{$R *.RES}


procedure RunApp; export;
begin
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end;

type
  TNewCPLInfo = record
    dwSize:        longint;   // similar to the commdlg
    dwFlags:       longint;
    dwHelpContext: longint;   // help context to use
    lData:         Longint; // user defined data
    Icon:          HICON;   // icon to use, this is owned by CONTROL.EXE (may be deleted)
    szName:        array[0..31] of Char;    // short name
    szInfo:        array[0..63] of Char;    // long name (status line)
    szHelpFile:    array[0..127] of Char;   // path to help file to use
  end;

function CPLApplet (hWndCpl: HWnd; msg: Word; lParam1: Longint;
                var NewCPLInfo: TNewCPLInfo): Longint; export;
begin
 beep;
 case msg of
  CPL_INIT: begin

    CPlApplet:=1;
   end;
   {CP asks "Are you an Applet"  We reply 1 - "Yes I am"}

  CPL_GETCOUNT:begin
   CPlApplet:=1;
  end;
   {CP asks "How many icons do you want"  We reply 1 - "One icon,
    please"}

  CPL_NEWINQUIRE:
   {CP sends this message once for every icon you require. In our
    case this is only sent once, so we dont need to concern ourself
    with what applet number CP wants to know about}
   begin

    with NewCPLInfo do begin
     dwSize:=sizeof(TNewCPLInfo);
     dwFlags := 0;
     dwHelpContext := 0;
     lData := 0;
     szHelpFile[0]:= #0;
     {Now comes the intersting bit; our icon and names}
     Icon := Application.Icon.Handle;
     StrPCopy(szName,'My First Applet');
     StrPCopy(szInfo,'My first Control Panel Applet (in Delphi!)');
    end;
   end;

  CPL_DBLCLK: RunApp;

 end;
end; //CPLApplet

exports
  RunApp,
  CPLApplet;

begin
end.
EOF---------------------------------------------

thanks for help
bernhard


Dipl. Ing. Bernhard Angerer
IFT / Vienna University of Technology
Karlsplatz 13/311
A-1040 Wien
Tel: +43 1 58801 3192
Fax: +43 1 504 14 97
angerer@mail.ift.tuwien.ac.at
0
Comment
Question by:angerer
  • 9
  • 7
  • 3
  • +3
23 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1359827
try adding  'stdcall' after exports
Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1359828
I mean

function RunApp;stdcall;

function CPLApplet (hWndCpl: HWnd; msg: Word; lParam1: Longint;
                    var NewCPLInfo: TNewCPLInfo): Longint; stdcall;

Igor
0
 
LVL 1

Author Comment

by:angerer
ID: 1359829
to inter: yes i know - but it does not work !

is the struct TNewCPLInfo correct ? the MS SDK help says:

LONG APIENTRY CPlApplet(
    HWND hwndCPl,      // handle to Control Panel window
    UINT uMsg,      // message
    LONG lParam1,      // first message parameter
    LONG lParam2       // second message parameter
   );

b.
0
 
LVL 5

Expert Comment

by:inter
ID: 1359830
Hi,
just add the 'packed record' instead of record to the TNewCplInfo. The following works as is

library TestCpl;

{$R *.res}

uses
  SysUtils, Windows, Messages, Dialogs, Classes,
  CPL;

function CPlApplet(hwndCPl: THandle; uMsg: DWORD; lParam1, lParam2: Longint): Longint;stdcall;
begin
  Result := 0;
  case uMsg of
    CPL_DYNAMIC_RES:;
    CPL_INIT:
    Result := 1; // 1 = Continue.
    CPL_GETCOUNT:
    Result := 1;
    CPL_INQUIRE:; // See CPL_NEWINQUIRE.
    CPL_SELECT:;
    CPL_DBLCLK, CPL_STARTWPARMS:
    // Pop up your dialog here...
    ShowMessage('Applet #' + IntToStr(lParam1) + ' selected');
    CPL_STOP:; // Control Panel is preparing to exit.
    CPL_EXIT:; // Control Panel is now exiting.
    CPL_NEWINQUIRE:
    begin
    with PNewCPLInfo(lParam2)^ do
    begin
    dwSize := SizeOf(TNewCPLInfo);
    hIcon := 0; // Use DLL's main icon. Make sure to include {$R *.res} above!!
    StrPCopy(@szName, 'Test');
    StrPCopy(@szInfo, 'This is a test Control Panel applet');
    end;
    Result := 1; // Don't call CPL_INQUIRE.
    end;
    CPL_SETUP:; // Internal. Used during system installation.
  end;
end;

exports
  CPlApplet;

begin
end.

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1359831
Try to make the record packed (TNewCPLInfo = packed record) or make sure that Project Option / Compiler / Align Record Fields is not checked.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359832
angerer,

I know of a freeware coponent, with heavely docs, great source, ... which (have you heard it before) does all this and more... yep. I don't know your problem, but I'm going to look at it. Meanwhile, I'll give you the URL to the component and I we all can look at the source :

home page : http://www.wilsonc.demon.co.uk/delphi.htm
component : http://www.wilsonc.demon.co.uk/Delphi Components/d3cpl.zip

Regards, Zif.

Let me know what you think of it.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359833
angerer,

maybe a silly question, but I still want to ask :

Why do you redeclare TNewCPLInfo, if it is already declared in cpl.pas?

PNewCPLInfoA = ^TNewCPLInfoA;
  PNewCPLInfoW = ^TNewCPLInfoW;
  PNewCPLInfo = PNewCPLInfoA;
  TNewCPLInfoA = packed record
    dwSize:        DWORD;   // similar to the commdlg
    dwFlags:       DWORD;
    dwHelpContext: DWORD;   // help context to use
    lData:         Longint; // user defined data
    hIcon:         HICON;   // icon to use, this is owned by CONTROL.EXE (may be deleted)
    szName:        array[0..31] of AnsiChar;    // short name
    szInfo:        array[0..63] of AnsiChar;    // long name (status line)
    szHelpFile:    array[0..127] of AnsiChar;   // path to help file to use
  end;
  TNewCPLInfoW = packed record
    dwSize:        DWORD;   // similar to the commdlg
    dwFlags:       DWORD;
    dwHelpContext: DWORD;   // help context to use
    lData:         Longint; // user defined data
    hIcon:         HICON;   // icon to use, this is owned by CONTROL.EXE (may be deleted)
    szName:        array[0..31] of WideChar;    // short name
    szInfo:        array[0..63] of WideChar;    // long name (status line)
    szHelpFile:    array[0..127] of WideChar;   // path to help file to use
  end;
  TNewCPLInfo = TNewCPLInfoA;

Zif?
0
 

Expert Comment

by:DPedrelli
ID: 1359834
Inprise has an FAQ on that with explanation & sample code:
http://www.inprise.com/devsupport/delphi/qanda/793.html

D.
0
 
LVL 1

Author Comment

by:angerer
ID: 1359835
Dear ZifNab !

I tried this component from the web and it works well !

thank you
bernhard
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359836
no problem. Glad I could help.

Shall I answer this question or not? I've only given you a link to a component... and 200 points for such a link is much...

Have a nice day and good luck with the component!

Zif.
0
 
LVL 1

Author Comment

by:angerer
ID: 1359837
Dear Zif !

yes you are right.
what do you do in this situation ?? (or what i have to do ?)


b.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1359838
What you can do is the following :

 1. Give a comment on this thread that it is solved and that you don't need any help with it.

Then :

 1. Ask linda gardner if she can reduce the points of this thread, and that we all agree on it.
 2. Ask a new question with less points and let me answer it/or somebody else or give points to everybody who helped you with this question (deviding is up to you).
 3. Do nothing.

It's up to you, I don't mind what you choose, everything is fine by me.

Zif.

It's up to you.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1359839
Take a look at Control Panel Applet:
http://www.wilsonc.demon.co.uk/delphi.htm#General Components
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359840
ronit, look at my comment of Date: Wednesday, August 05 1998 - 11:17AM PDT, Zif.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1359841
Take a look at Control Panel Applet:
http://www.wilsonc.demon.co.uk/delphi.htm#General Components
0
 
LVL 1

Author Comment

by:angerer
ID: 1359842
Dear Zif !

yes - thank you it is solved - but how can i reach linda gardner ??


ciao
b.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359843
angerer,

 I last the e-mail myself....

 but post a 0 question to customer service :

  http://www.experts-exchange.com/browsing/experts-exchange/

 and explain them what you want.

Regards, Zif.
0
 
LVL 1

Author Comment

by:angerer
ID: 1359844
Dear Zif !

please close the question with the 200 points.


ciao
b.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1359845
angerer,

 problems with changing it? customer service is run by linda gardner!

Zif.
0
 
LVL 1

Author Comment

by:angerer
ID: 1359846
Thanks for the help !

i think your service is very good. there is one thing missing: an intelligent way to find allready answered questions.

do you know a good 'Knowledge Base' on the Web.


ciao
bernhard
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359847
bernhard,

 at http://www.experts-exchange.com there is now a search utility.

 second at chamis place(which combines several databases).

 Reach by Delphi Deli : http://delphi.lehner.at/

Regards, Zif.
0
 
LVL 1

Author Comment

by:angerer
ID: 1359848
Search Utility at Expert Exchange : sorry i dont find it - where is it ??

Chamis Place: i know this site - thanks

delphi.lehner.at: i could not reach it ??


b.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359849
look at  http://www.experts-exchange.com, on the top left, you can find search button.

deli has problems I think.

And another good one is :

http://developers.href.com/

Zif.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now