Click here to Skip to main content
Click here to Skip to main content
Go to top

System Dialogs

, , 21 Aug 2004
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

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

Comments and Discussions

 
GeneralAdded TimeZone Pinmembercsevb1014-Dec-04 11:08 
GeneralRe: Added TimeZone PinmemberA. Riazi14-Dec-04 20:13 

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 | Mobile
Web02 | 2.8.140916.1 | Last Updated 22 Aug 2004
Article Copyright 2004 by A. Riazi, Shafiee
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid