Click here to Skip to main content
Click here to Skip to main content

System Dialogs

By , , 21 Aug 2004
 

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

About the Authors

A. Riazi
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Member
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)
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberasef18 Mar '12 - 1:26 
Got my 5
GeneralMy vote of 5membermanoj kumar choubey26 Feb '12 - 19:56 
Nice
GeneralGreat One.......membersandeep.ym12 Nov '09 - 21:54 
Its really nice and cute.........thanks........my friend..........Thumbs Up | :thumbsup:
GeneralReally nice articlemembermdhanif19 Aug '07 - 20:19 
Thanks for your nice ,simple and very useful article.
 
Regards,
KSMH
GeneralVista compatibility - SD_DEVICE_MANAGER brokenmemberAnarchi5 Apr '07 - 18:20 
SD_DEVICE_MANAGER seems to be broken under Vista.
 
Do we need to load a different Vista dll instead of XP's devmgr.dll ?
QuestionReally great. one Riazi.....memberS.Mnikandan24 Oct '06 - 11:23 
hi....
its really grt one...
 
In the same way i have found the function to invoke photo printing wizard in photowiz.dll .
but i couldn't find the input parameters.could u plz throw some light on how to find it ? or can u tell me how to invoke it with rundll32? i tried with different inputs and diff combinations...(not able to get output Frown | :(
 
Thanks in advance Smile | :)
 

Mani

Joketo show network connectionmemberJetli Jerry15 Jun '06 - 20:50 
hi
 
gGood Article.
 
To show network connections use "ncpa.cpl" of shell32.dll Control_RunDLL(a/W)
 
Cool | :cool:
 

 
Jetli
Constant Thing In World Is Change.
QuestionData Link Properties Dialogmemberrohitshrivastava2 May '06 - 21:09 
Hi
Please tell me how can I open Data Link properties dialog that is used to set database connection properties.
 
Thanks
Rohit
 
Rohit Shrivastava
QuestionShutdown dialog?memberpeterchen16 Mar '06 - 5:38 
Do you have any idea how to display the shutdown dialog?
 

 


Some of us walk the memory lane, others plummet into a rabbit hole

Tree in C# || Fold With Us! || sighist
QuestionWhy separate ANSI and UNICODE?memberpeterchen2 Dec '05 - 2:38 
Is there a reason you sued two separate tables for ANSI and UNICODE, rather than a single one which contains both strings?
 


We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.

boost your code || Fold With Us! || sighist
GeneralOpenAs Dialogmembergjyfromlz20 Jun '05 - 0:59 
how can I open an OpenAs Dialog?(when I doubleclick a special file for example: 1.dllx ,the system automatic popup the dialog).Thank u very much.Laugh | :laugh:
 
develop
GeneralRe: OpenAs Dialogmembergjyfromlz20 Jun '05 - 21:59 
I found the answer:
{_OPEN_AS_DIALOG, ("Shell32.dll"), "OpenAs_RunDLL", " c:\\1.dllx"}
 

 
develop
GeneralUse of System Dialogsmembergerminara4 Apr '05 - 22:42 
Hello, I'm a sw developer, I used your class italian software SystemDialog and I build a new little application "Panel Palette" written in MFC.
I want to give it free to anyone want to use it, i'm going to publish this on my web site.
 
Can I use your sample code and can I put your name and references on the About Box of the applications.
 
My sites is www.germinara.it (it's italian language only).
 
Thanks and best regards.
 
Francesco Germinara
Please Reply Address: franco@germinara.it

GeneralRe: Use of System DialogsmemberA. Riazi4 Apr '05 - 22:49 
Dear Francesco,
Hi. Thank you for you comment. There is no restriction to use my code. You are free to use/modify it. Hope enjoying the code.
 
Best regards,
A. Riazi

QuestionHow to call &quot;safely remove hardware&quot; dialogmemberizne3 Feb '05 - 16:43 
aslm. very good article. got my 5.
 
I am trying to pop up the safely remove hardware dialog (in winxp or win2k to remove usb thumb drive) using your method. The question is how and where can i find the dll that contains that particular dialog? Thank you
AnswerRe: How to call &quot;safely remove hardware&quot; dialogsussAnonymous2 Mar '05 - 6:09 
First I have to join people who is VERY happy with the work done here.... Excellent!
Answer to your question is:
_T("Shell32.dll"), "Control_RunDLLA", "hotplug.dll"
 

Tested on ME and XP only.
GeneralAdded TimeZonemembercsevb1014 Dec '04 - 11:08 
Great simple class. I needed just such an example, and here it was.
 
Acutally, I wanted to open up the TimeZone tab of the Date/Time control panel. But with the head start you provided I discovered that changing

{SD_DATE_TIME, _T("Shell32.dll"), "Control_RunDLLA", "timedate.cpl"},

 
to....
 

{SD_DATE_TIME, _T("Shell32.dll"), "Control_RunDLLA", "timedate.cpl,,1"},

 
Popped up the second tab (I still don't know what the other missing argument is, but it works).
 
So, I modified your class a wee bit to include the ability to pull up a specific Tab on the various control panels programmatically.
 
Anyway...Thanks for the class Smile | :)
 
PAC
GeneralRe: Added TimeZonememberA. Riazi14 Dec '04 - 20:13 
Cool | :cool:
 
A. Riazi
Generalhelp me with the audio setup wizardmemberRenato Czar Tome9 Nov '04 - 14:52 
i want to have like audio setup wizard for all platforms, thanks.Blush | :O
Generalvery goodmemberMahmood Komeily13 Sep '04 - 7:50 
hey abbas,i enjoy from this article.
it was very good
sincerely
Smile | :)
GeneralFolde properties dialogmemberHugo Hallman2 Sep '04 - 23:23 
I'm looking for a way to open a file system folder system dialog. Do you know how to do it?
-Excellent library too!Smile | :)
GeneralVery clever!memberJörgen Sigvardsson28 Aug '04 - 13:14 
I have bookmarked this article for future reference. Smile | :)
 
--
...Coca Cola, sometimes war...
GeneralRe: Very clever!memberA. Riazi28 Aug '04 - 18:49 
Thank you for your comment. Smile | :)
 
A. Riazi

GeneralSHFormatDrive declarationmemberjarvisa24 Aug '04 - 22:28 
According to Microsoft documentation SHFormatDrive has the following declaration:
 
DWORD SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options);

GeneralOpening IIS DialogmemberLizardKingSchwing24 Aug '04 - 5:05 
Any Idea how to open IIS Dialog ???
 
Cheers
 
LK--<

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

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