Undocumented Windows® Functions
Applies To: C++Builder 1 or higher
Category: Technical Articles
- Introduction
-
- Windows provides you a complete set of common dialogs and shell functions such as the OpenFile or PrinterSetup dialog. But sometimes you need a special system dialog that looks exactly like the one used by Windows. I've always wondered how to display the Properties dialog for a particular file or how to show the FindFiles wizard.
-

-
- Exporting Functions
-
- All special shell common dialog functions that you need can be exported from SHELL32.DLL This is basically done by dynamically loading the .DLL and then getting the address of a particular function.
-
- Probably the simplest function you can find in this .DLL is ExitWindowsDialog. It shows the dialog that is displayed when you click on Start Menu | Shut Down... The ordinal value of this particular function is 60 and its declaration is:
-
- void WINAPI ExitWindowsDialog(
- HWND hwndOwner);
-
- ExitWindowsDialog Example
-
- Start a new application.
-
- Insert in your source code:
-
- typedef void (__stdcall *pExitWindowsDialog)(HWND);
-
- HINSTANCE hInstance;
- pExitWindowsDialog ExitWindowsDialog;
-
- Edit the OnCreate event of your form:
-
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- hInstance = LoadLibrary("SHELL32.DLL");
- if(!hInstance)
- {
- ShowMessage("Error loading SHELL32.DLL\n"
- "This application will be closed");
- Application->Terminate();
- }
-
- ExitWindowsDialog = (pExitWindowsDialog)
- GetProcAddress(hInstance, (char *)60);
- }
-
- Double-click the OnDestroy event:
-
- void __fastcall TForm1::FormDestroy(TObject *Sender)
- {
- FreeLibrary(hInstance);
- }
-
- Finally, add the Button and open its OnClick event:
-
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- ExitWindowsDialog(Handle);
- }
-
- This code uses the typedef keyword to represent the ExitWindowsDialog undocumented function. When the main form is created, the application tries to load SHELL32.DLL and export the function we want. Finally, the Button displays the appropriate dialog.
-
- ObjectProperties Dialog
-
- ExitWindowsDialog is a very simple and useless function. But what about a more complex one, such as SHObjectProperties. SHObjectProperties shows the Properties dialog for a file, a folder or a printer. It's ordinal value is 178 and the function declaration is:
-
- BOOL WINAPI SHObjectProperties(
- HWND hwndOwner,
- UINT uFlags,
- LPCSTR lpstrName,
- LPCSTR lpstrParameters);
-
- hwndOwner is of course the handle of the window that owns this dialog. uFlags specifies whether lpstrName points to a file name or printer object name. Finally, lpstrParameters specifies the name of the page that will be selected at start-up. Use NULL for the default one.
Compatibility: For Windows NT applications, it is recommended to replace the LPCSTR type by LPCWSTR.
-
- SHObjectProperties Example
-
- Start a new application.
-
- Insert in your source code:
-
- typedef void (__stdcall *pSHObjectProperties)(HWND, UINT, LPCSTR,
- LPCSTR);
-
- HINSTANCE hInstance;
- pSHObjectProperties SHObjectProperties;
-
- Edit the OnCreate event of your form:
-
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- hInstance = LoadLibrary("SHELL32.DLL");
- if(!hInstance)
- {
- ShowMessage("Error loading SHELL32.DLL\n"
- "This application will be closed");
- Application->Terminate();
- }
-
- SHObjectProperties = (pSHObjectProperties)
- GetProcAddress(hInstance, (char *)178);
- }
-
- Double-click the OnDestroy event:
-
- void __fastcall TForm1::FormDestroy(TObject *Sender)
- {
- FreeLibrary(hInstance);
- }
-
- Add a Button. Edit its OnClick event:
-
- #define OPF_PRINTERNAME 0x01
- #define OPF_PATHNAME 0x02
-
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- SHObjectProperties(Handle, OPF_PATHNAME,
- "c:\\autoexec.bat", NULL);
- }
-
- Once the Button is clicked, the application should show the Properties dialog for autoexec.bat.
-
- Conclusion
-
- As you can see, dynamically loading SHELL32.DLL is not very difficult and it allows you to save time by using already created dialogs. For a complete list and description of undocumented functions you can use, visit:
-
- Undocumented Windows 95
C++Builder Developer's Network
Copyright © Yoto Yotov