Click here to Skip to main content
11,718,013 members (80,033 online)
Click here to Skip to main content

System Dialogs

, , 21 Aug 2004 CPOL 123.6K 2.7K 96
Rate this:
Please Sign up or sign in to vote.
This article shows you a very simple way to show system dialogs like Internet Options, Add/Remove Programs, and etc.

Sample Image - SystemDialogs.jpg

Introduction

RunDll32.exe is one of the most useful tools that Microsoft developed first for internal use, but because of wide application of this simple utility, delivered to developers. With this simple utility, one can launch system dialogs like applets of Control Panel or dialogs that are hidden in some DLLs like Format dialog or Device Manager Property Sheet dialog.

For testing the Rundll32.exe, it's enough to click the Start button then choose Run... from Start menu, and type this syntax:

Rundll32.exe <name of dll> <entry point function> <arguments>

For example, for launching the Format dialog, it's enough to run this statement:

Rundll32.exe Shell32.dll SHFormatDrive

Shell32.dll is a DLL that hides the Format Dialog and SHFormatDrive is the entry point function for launching the Format dialog.

RunDll32 Internal

The entry point function that Rundll32.exe tries to load has the syntax shown below (for Unicode):

void <entry point function> (HWND hwndStub, HINSTANCE hAppInstance, 
                LPWSTR lpCmdLine, int nCmdShow);

and for ANSI:

void <entry point function> (HWND hwndStub, HINSTANCE hAppInstance, 
                LPSTR lpCmdLine, int nCmdShow);

hwndStub is the handle of a window that calls the function. hAppInstance is the instance handle of the application, lpCmdLine is the command line argument of the entry point, and nCmdShow specifies how to show the dialog.

The RunDll32.dll simply loads the library (*.dll), then try loading the desired function by using GetProcAddress(). We can also do this by writing this code:

#ifdef _UNICODE 
typedef void (_stdcall *PFUNCTION_ENTRYPOINT)(HWND hwndStub, 
                    HINSTANCE hAppInstance, 
                    LPWSTR lpCmdLine,
                    int    nCmdShow);

#else
typedef void (_stdcall *PFUNCTION_ENTRYPOINT)(HWND hwndStub, 
                    HINSTANCE hAppInstance,
                    LPSTR lpCmdLine,
                    int    nCmdShow);
#endif

PFUNCTION_ENTRYPOINT pEntryPoint=NULL;
HINSTANCE hInst=AfxGetInstanceHandle();
HMODULE  hModule = LoadLibrary(DllName);        
if (hModule) 
{
    pEntryPoint = (PFUNCTION_ENTRYPOINT) GetProcAddress(hModule, FunctionName);
}
            
if (pEntryPoint)
{
    pEntryPoint(hParent, hInst, CommandLine, SW_SHOW);
}

CSystemDialog

CSystemDialog is a very simple class to do this stuff automatically. It has only one member function:

void DoModal(int iDialogID, HWND hParent);

iDialogID is the identifier of the dialog and hParent is the handle of the main window of your program. Here is an example:

CSystemDialog dlg;
dlg.DoModal(SD_GAME_CONTROLLERS, m_hWnd);

The definition of the class is as below:

#ifndef _SYSTEM_DIALOGS_H_
#define _SYSTEM_DIALOGS_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define SD_FORMAT             1
#define SD_INTERNET_OPTIONS         2
#define SD_ADD_REMOVE_PROGRAMS         3
#define SD_DATE_TIME             4
#define SD_DISPLAY            5
#define SD_MODEM            6
#define SD_MULTIMEDIA            7
#define SD_MOUSE            8
#define SD_NETWORK            9
#define SD_PASSWORD            10
#define SD_SYSTEM            11
#define SD_REGIONAL_SETTINGS         12
#define SD_SOUNDS            13
#define SD_GAME_CONTROLLERS        14
#define SD_KEYBOARD            15
#define SD_DEVICE_MANAGER        16


typedef struct tagSystemDialog
{
    int iSystemDialogID;
    TCHAR cDllName[100];
    char cFuncName[256];
    TCHAR cCommand[100];

} SystemDialog;

class CSystemDialog  
{
public:
    void DoModal(int iDialogID, HWND hParent);
    CSystemDialog();
    virtual ~CSystemDialog();
};

#endif // _SYSTEM_DIALOGS_H_

Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

A. Riazi
CEO Misbah3Com
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acqusition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competetion, my articles are:

You can see list of my articles, by clicking here


Shafiee
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralFolde properties dialog Pin
Hugo Hallman2-Sep-04 23:23
memberHugo Hallman2-Sep-04 23:23 
GeneralVery clever! Pin
Jörgen Sigvardsson28-Aug-04 13:14
memberJörgen Sigvardsson28-Aug-04 13:14 
GeneralRe: Very clever! Pin
A. Riazi28-Aug-04 18:49
memberA. Riazi28-Aug-04 18:49 
GeneralSHFormatDrive declaration Pin
jarvisa24-Aug-04 22:28
memberjarvisa24-Aug-04 22:28 
GeneralOpening IIS Dialog Pin
LizardKingSchwing24-Aug-04 5:05
memberLizardKingSchwing24-Aug-04 5:05 
GeneralRe: Opening IIS Dialog Pin
Jigar Mehta7-Oct-04 18:38
memberJigar Mehta7-Oct-04 18:38 
GeneralRe: Opening IIS Dialog Pin
LizardKingSchwing7-Oct-04 22:28
memberLizardKingSchwing7-Oct-04 22:28 
Generalgood project Pin
foxsermon24-Aug-04 4:18
memberfoxsermon24-Aug-04 4:18 
a few months ago, I was looking the answer to my question, but now I read your article and run your project everything is clear. Good Project indeed !!

Smile | :)

Foxy Big Grin | :-D
GeneralSuperb Pin
dp @ IIITH23-Aug-04 19:38
sussdp @ IIITH23-Aug-04 19:38 
GeneralRe: Superb Pin
A. Riazi23-Aug-04 20:38
memberA. Riazi23-Aug-04 20:38 
Generalgreat work Pin
m a y s a m23-Aug-04 19:36
memberm a y s a m23-Aug-04 19:36 
GeneralRe: great work Pin
A. Riazi23-Aug-04 20:52
memberA. Riazi23-Aug-04 20:52 
Generalsuper, 2 little questions Pin
Dieter Hammer22-Aug-04 21:48
memberDieter Hammer22-Aug-04 21:48 
GeneralRe: super, 2 little questions Pin
A. Riazi22-Aug-04 22:40
memberA. Riazi22-Aug-04 22:40 
GeneralAccess control Pin
Alex Evans22-Aug-04 13:44
memberAlex Evans22-Aug-04 13:44 
GeneralRe: Access control Pin
JOHN1123-Aug-04 22:28
memberJOHN1123-Aug-04 22:28 
GeneralAnother great article.. Pin
Robert Buldoc22-Aug-04 9:17
memberRobert Buldoc22-Aug-04 9:17 
GeneralRe: Another great article.. Pin
A. Riazi22-Aug-04 23:01
memberA. Riazi22-Aug-04 23:01 
GeneralVery nice !!! Pin
zilog71822-Aug-04 8:32
memberzilog71822-Aug-04 8:32 
GeneralRe: Very nice !!! Pin
A. Riazi22-Aug-04 23:02
memberA. Riazi22-Aug-04 23:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150901.1 | Last Updated 22 Aug 2004
Article Copyright 2004 by A. Riazi, Shafiee
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid