Control Panel Application

Hi,

I'd like to write a Control Panel Application, using Visual C++ 6.
I know that I must write a kind of dll that treats CPL messages and I've read the corresponding MSDN help.

But the code I've written doesn't work.
Here is it:

//I've created a win32 dll project
//Then, I've deleted the dll entry point function.
//Here beyond is my code
#include "stdafx.h"

LONG CALLBACK CPlApplet(HWND hWndCPL, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{
  MessageBox(hWndCPL, "Begin of CPlApplet", "Debug info", /* all the styles I need */);
  return 0;
}

I think CPlApplet should become the standard entry point for control panel application. But when I put the compiled file (yes, it compiles without any problem) in the Windows\System directory and then launch the file, nothing happens.

Can anyone help me?
Why doesn't the message box appear?
At least, do you know any web site where a simple example of such a cpl-app is given?
LVL 1
DeckmeisterAsked:
Who is Participating?
 
WynCommented:
0
 
WynCommented:
www.codeguru.com has an example.
Regards
W.Yinan
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DeckmeisterAuthor Commented:
Well, I've found on codeguru a CPL example, but it is written using MFC.
And I just want to write a C-like dll and not to use MFC.

Moreover, I've given 70 points to the question.
So, you could at least tell me why my code doesn't work.
0
 
DeckmeisterAuthor Commented:
Wyn>
Ok, as I rejected your answer, I still haven't seen the further comments you made.

I am now ready to give you points if you:
- tell me why my code doesn't work
- tell me if I need to write a dllMain function or not (I think not, but I don't really know).

If you give me an ANSWER to these two questions, I will give you the points.
0
 
vbk_bgmCommented:
- tell me why my code doesn't work
- tell me if I need to write a dllMain function or not (I think not, but I don't really know).

Your code might not work for the foll reasons.
1 Add the DLL entry point DllMain
2 Add CPlApplet as one of the exports in the .def file for the DLL
0
 
danelroismanCommented:
Creating Control Panel Applications
Every Control Panel application is a dynamic-link library. However, the DLL file must have a .cpl file name extension. For Windows 2000 and later systems, new Control Panel applications should be installed in the associated application's folder under the Program Files folder. The DLL's path must be registered in one of two ways:

If the Control Panel application is to be available to all users, register the path on a per-computer basis by adding a REG_EXPAND_SZ value to the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Control Panel\Cpls key, set to the DLL path.
If the Control Panel application is to be available on a per-user basis, use HKEY_CURRENT_USER as the root key instead of HKEY_LOCAL_MACHINE.
The following two examples register the MyCplApp Control Panel application. The DLL is named MyCpl.cpl and is located in the MyCorp\MyApp application directory. The first registry entry illustrates per-computer registration, and the second illustrates per-user registration.

HKEY_LOCAL_MACHINE
    Software
        Microsoft
            Windows
                CurrentVersion
                    Control Panel
                        Cpls
                            MyCpl="%ProgramFiles%\MyCorp\MyApp\MyCpl.cpl"

-or-

HKEY_CURRENT_USER
    Software
        Microsoft
            Windows
                CurrentVersion
                    Control Panel
                        Cpls
                            MyCpl="%ProgramFiles%\MyCorp\MyApp\MyCpl.cpl"

For systems prior to Windows 2000, new Control Panel applications must be set up in one of the following ways:

Copy the DLL to the directory that contains the Windows system utility.
Copy the DLL to the Windows SYSTEM directory.
Write the path of the DLL using the WritePrivateProfileString function, specifying the string "MMCPL" as the section name and the string "control.ini" as the file name (no path). Do not actually write directly to the control.ini file. Instead, use the WritePrivateProfileString function, which automatically handles differences among platforms. The following example demonstrates how you would set up the path for MyCpl.cpl.
WritePrivateProfileString("MMCPL",
                          "MyCpl.cpl",
                          "C:\\mydir\\MyCpl.cpl",
                          "control.ini");

Note control.ini can also restrict which Control Panel applications are loaded. It is not recommended that applications alter Control.ini for this purpose.



Although a Control Panel application can support more than one subprogram, it processes all requests through the single CPlApplet function. In the following example, the Control Panel application supports three subprograms that let the user set preferences for a component stereo system attached to the computer. The example uses an application-defined StereoSubProgs array that contains three structures, each corresponding to one of the subprograms. Each structure contains all the information required by the CPL_INQUIRE message as well as the dialog box template and dialog box procedure required by the CPL_DBLCLK message. The code demonstrates how to fill the structures in the StereoSubProgs array.

#define NUM_SUBPROGS 3
 
typedef struct tagSubProg
{
    int icon;         // icon resource identifier
    int namestring;   // name-string resource identifier
    int descstring;   // description-string resource identifier
    int dlgtemplate;  // dialog box template resource identifier
    DLGPROC dlgfn;    // dialog box procedure
} SUBPROG;
 
SUBPROG StereoSubProgs[NUM_SUBPROGS] =
{
    AMP_ICON, AMP_NAME, AMP_DESC, AMP_DLG, AmpDlgProc,
    TUNER_ICON, TUNER_NAME, TUNER_DESC, TUNER_DLG, TunerDlgProc,
    TAPE_ICON, TAPE_NAME, TAPE_DESC, TAPE_DLG, TapeDlgProc,
};

HANDLE  hinst = NULL;

LONG CALLBACK CPlApplet(hwndCPL, uMsg, lParam1, lParam2)
HWND hwndCPL;      // handle to Control Panel window
UINT uMsg;         // message
LPARAM lParam1;    // first message parameter
LPARAM lParam2;    // second message parameter
{
    int i;
    LPCPLINFO lpCPlInfo;
 
    i = (int) lParam1;
 
    switch (uMsg) {
        case CPL_INIT:      // first message, sent once
            hinst = GetModuleHandle("ecp.cpl");
            return TRUE;
 
        case CPL_GETCOUNT:  // second message, sent once
            return NUM_SUBPROGS;
            break;
 
        case CPL_INQUIRE: // third message, sent once per application
            lpCPlInfo = (LPCPLINFO) lParam2;
            lpCPlInfo->lData = 0;
            lpCPlInfo->idIcon = StereoSubProgs[i].icon;
            lpCPlInfo->idName = StereoSubProgs[i].namestring;
            lpCPlInfo->idInfo = StereoSubProgs[i].descstring;
            break;

        case CPL_DBLCLK:    // application icon double-clicked
            DialogBox(hinst,
                MAKEINTRESOURCE(StereoSubProgs[i].dlgtemplate),
                hwndCPL, StereoSubProgs[i].dlgfn);
            break;
 
        case CPL_STOP:      // sent once per application before CPL_EXIT
            break;
 
        case CPL_EXIT:    // sent once before FreeLibrary is called
            break;
 
        default:
            break;
    }
    return 0;
}


There are two ways to start a Control Panel application:

The user can open Control Panel and start an application by double-clicking the application icon.
The user or an application can start a Control Panel application by executing it directly from the command line prompt.
The following example shows how an application can start the Control Panel application named MyCpl.cpl by using the WinExec function.

WinExec("control.exe MyCpl.cpl", SW_NORMAL);





0
 
DeckmeisterAuthor Commented:
danelroisman>
- Your answer doesn't indicate me what is wrong with my code.
- I've said (in my question) that I've read the MSDN help corresponding to CPL-applets. So I don't understand why you give me the MSDN example code.

Wyn>
I accept your answer, because you were really fast answering to my question.
And your comments and links to website have helped me a lot.
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.