Solved

Control Panel Application

Posted on 2000-02-29
8
691 Views
Last Modified: 2008-03-17
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?
0
Comment
Question by:Deckmeister
8 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2571693
www.codeguru.com has an example.
Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2571708
0
 
LVL 5

Accepted Solution

by:
Wyn earned 70 total points
ID: 2571719
0
 
LVL 1

Author Comment

by:Deckmeister
ID: 2571727
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Author Comment

by:Deckmeister
ID: 2571748
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
 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2571832
- 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
 
LVL 2

Expert Comment

by:danelroisman
ID: 2572008
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
 
LVL 1

Author Comment

by:Deckmeister
ID: 2572153
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

Featured Post

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.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

708 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

13 Experts available now in Live!

Get 1:1 Help Now