Click here to Skip to main content
15,436,185 members
Articles / Programming Languages / C
Posted 21 Aug 2004


98 bookmarked

System Dialogs

Rate me:
Please Sign up or sign in to vote.
4.89/5 (68 votes)
21 Aug 2004CPOL1 min read
This article shows you a very simple way to show system dialogs like Internet Options, Add/Remove Programs, and etc.

Sample Image - SystemDialogs.jpg


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);

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

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


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:


#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  
    void DoModal(int iDialogID, HWND hParent);
    virtual ~CSystemDialog();

#endif // _SYSTEM_DIALOGS_H_



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

Written By
CEO Solaris Electronics LLC
United Arab Emirates United Arab Emirates
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 Acquisition 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 competition, my articles are:

You can see list of my articles, by clicking here

Written By
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralMy vote of 5 Pin
asef18-Mar-12 1:26
Memberasef18-Mar-12 1:26 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 19:56
professionalManoj Kumar Choubey26-Feb-12 19:56 
GeneralGreat One....... Pin
sandeep.ym12-Nov-09 21:54
Membersandeep.ym12-Nov-09 21:54 
GeneralReally nice article Pin
mdhanif19-Aug-07 20:19
Membermdhanif19-Aug-07 20:19 
GeneralVista compatibility - SD_DEVICE_MANAGER broken Pin
Anarchi5-Apr-07 18:20
MemberAnarchi5-Apr-07 18:20 
QuestionReally great. one Riazi..... Pin
S.Mnikandan24-Oct-06 11:23
MemberS.Mnikandan24-Oct-06 11:23 
Joketo show network connection Pin
Jetli Jerry15-Jun-06 20:50
MemberJetli Jerry15-Jun-06 20:50 
QuestionData Link Properties Dialog Pin
rohitshrivastava2-May-06 21:09
Memberrohitshrivastava2-May-06 21:09 
QuestionShutdown dialog? Pin
peterchen16-Mar-06 5:38
Memberpeterchen16-Mar-06 5:38 
QuestionWhy separate ANSI and UNICODE? Pin
peterchen2-Dec-05 2:38
Memberpeterchen2-Dec-05 2:38 
GeneralOpenAs Dialog Pin
gjyfromlz20-Jun-05 0:59
Membergjyfromlz20-Jun-05 0:59 
GeneralRe: OpenAs Dialog Pin
gjyfromlz20-Jun-05 21:59
Membergjyfromlz20-Jun-05 21:59 
GeneralUse of System Dialogs Pin
germinara4-Apr-05 22:42
Membergerminara4-Apr-05 22:42 
GeneralRe: Use of System Dialogs Pin
Abbas_Riazi4-Apr-05 22:49
professionalAbbas_Riazi4-Apr-05 22:49 
QuestionHow to call &quot;safely remove hardware&quot; dialog Pin
izne3-Feb-05 16:43
Memberizne3-Feb-05 16:43 
AnswerRe: How to call &quot;safely remove hardware&quot; dialog Pin
Anonymous2-Mar-05 6:09
MemberAnonymous2-Mar-05 6:09 
GeneralAdded TimeZone Pin
csevb1014-Dec-04 11:08
Membercsevb1014-Dec-04 11:08 
GeneralRe: Added TimeZone Pin
Abbas_Riazi14-Dec-04 20:13
professionalAbbas_Riazi14-Dec-04 20:13 
Generalhelp me with the audio setup wizard Pin
renato tome9-Nov-04 14:52
Memberrenato tome9-Nov-04 14:52 
Generalvery good Pin
Mahmoud Komeily13-Sep-04 7:50
MemberMahmoud Komeily13-Sep-04 7:50 
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
Abbas_Riazi28-Aug-04 18:49
professionalAbbas_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 

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

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