home *** CD-ROM | disk | FTP | other *** search
- /*
- XCSTODS.C -- Uses a better way than XCStoDS to get USER's DS
-
- From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC XCSTODS (for Borland C++ v3.00)
- WINIOMS XCSTODS (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include <dos.h>
- #include <string.h>
- #include "winio.h"
-
- #ifndef __BORLANDC__
- #define MK_FP(a,b) ((void far *)(((unsigned long)(a) << 16) | (b)))
- #endif
-
- /* Undocumented structures */
- #include "userobj.h"
-
- /* undocumented function that could be used in 3.0 */
- // extern WORD FAR PASCAL XCStoDS(void);
-
- WORD selUserDS;
- char strIndent[30] = {0};
- char strText[128];
-
- void printtree(WORD wndofs)
- {
- // We only need WND fields which coincide in 3.0 and 3.1
- WND_3_0 far *hwnd;
-
- for (;;)
- {
- hwnd = MK_FP(selUserDS, wndofs);
- GetWindowText((HWND) wndofs, (LPSTR) &strText, 128);
- printf("%sWindow %04X is %s\n", strIndent, wndofs, strText);
- if (hwnd->hwndChild != NULL)
- {
- int i = strlen(strIndent);
- strcat(strIndent, " ");
- printtree(hwnd->hwndChild);
- strIndent[i] = 0;
- }
- if ((wndofs = hwnd->hwndNext) == NULL)
- break;
- }
- }
-
-
- int main()
- {
- winio_about("XCSTODS"
- "\nShows how access to USER's default DS might be used"
- "\n\nFrom Chapter 6 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- // The following line will only work in 3.0
- // selUserDS = XCStoDS();
- // whereas the following line will work in 3.0 and 3.1
- selUserDS = GetWindowWord(GetDesktopWindow(), GWW_HINSTANCE);
-
- // Now we need to adjust the selector privilege level for 3.0
- selUserDS &= 0xfffc;
- selUserDS |= 1;
-
- // Build the list, then paint it
- winio_setpaint(winio_current(), FALSE);
-
- printtree(GetDesktopWindow());
-
- puts("\n\nEnd **********");
-
- winio_setpaint(winio_current(), TRUE);
-
- winio_home(winio_current());
-
- return 0;
- }
-