Posted: . At: 9:08 AM. This was 2 years ago. Post ID: 16256
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Very interesting Windows XP source code samples.


I have found some very interesting Windows XP source code. This is the source code of the Autorun functionality.

autorun\autorun.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <windows.h>
#include "autorun.h"
#include "resource.h"
#include "dlgapp.h"
#include "util.h"
 
// FIRST ITEM MUST ALWAYS BE EXIT_AUTORUN
const int c_aiMain[] = {EXIT_AUTORUN, INSTALL_WINNT, SUPPORT_TOOLS, COMPAT_TOOLS}; 
const int c_aiWhistler[] = {EXIT_AUTORUN, INSTALL_WINNT, LAUNCH_ARP, SUPPORT_TOOLS, COMPAT_TOOLS};
 
// IA64 gets bare options, Server SKUs get minimal options, Professional and Personal get full options
#if defined(_IA64_)
const int c_aiSupport[] = {EXIT_AUTORUN, BROWSE_CD, VIEW_RELNOTES, INSTALL_CLR, BACK};
#else
#if BUILD_SERVER_VERSION | BUILD_ADVANCED_SERVER_VERSION | BUILD_DATACENTER_VERSION | BUILD_BLADE_VERSION | BUILD_SMALL_BUSINESS_VERSION
const int c_aiSupport[] = {EXIT_AUTORUN, TS_CLIENT, BROWSE_CD, VIEW_RELNOTES, INSTALL_CLR, BACK};
#else
const int c_aiSupport[] = {EXIT_AUTORUN, TS_CLIENT, HOMENET_WIZ, MIGRATION_WIZ, BROWSE_CD, VIEW_RELNOTES, INSTALL_CLR, BACK};
#endif
#endif
 
const int c_aiCompat[] = {EXIT_AUTORUN, COMPAT_LOCAL, COMPAT_WEB, BACK};
 
const int c_cMain = ARRAYSIZE(c_aiMain);
const int c_cWhistler = ARRAYSIZE(c_aiWhistler);
const int c_cSupport = ARRAYSIZE(c_aiSupport);
const int c_cCompat = ARRAYSIZE(c_aiCompat);
 
// Code to ensure only one instance of a particular window is running
HANDLE CheckForOtherInstance(HINSTANCE hInstance)
{
    TCHAR   szCaption[128];
    HANDLE  hMutex;
 
    LoadStringAuto(hInstance, IDS_TITLEBAR, szCaption, 128);
 
    // We create a named mutex with our window caption just as a way to check
    // if we are already running autorun.exe.  Only if we are the first to
    // create the mutex do we continue.
 
    hMutex = CreateMutex (NULL, FALSE, szCaption);
 
    if ( !hMutex )
    {
        // failed to create the mutex
        return 0;
    }
    else if (GetLastError() == ERROR_ALREADY_EXISTS)
    {
        // Mutex created but by someone else, activate that window
        HWND hwnd = FindWindow( WINDOW_CLASS, szCaption );
        SetForegroundWindow(hwnd);
        CloseHandle(hMutex);
        return 0;
    }
 
    // we are the first
    return hMutex;
}
 
/**
*  This function is the main entry point into our application.
*
*  @return     int     Exit code.
*/
 
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin, int nShowCmd )
{
    HANDLE hMutex = CheckForOtherInstance(hInstance);
 
    if ( hMutex )
    {
        CDlgApp dlgapp;
        dlgapp.Register(hInstance);
        if ( dlgapp.InitializeData(lpCmdLin) )
        {
            dlgapp.Create(nShowCmd);
            dlgapp.MessageLoop();
        }
 
        CloseHandle(hMutex);
    }
    return 0;
}

And this is the autorun.h include file.

autorun/autorun.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once
 
#define WINDOW_CLASS    TEXT("_WindowsAutorunSetup_")
 
#define INSTALL_WINNT   0
#define LAUNCH_ARP      1
#define SUPPORT_TOOLS   2
#define EXIT_AUTORUN    3
#define BACK            4
#define MIGRATION_WIZ   5
#define HOMENET_WIZ     6
#define TS_CLIENT       7
#define COMPAT_WEB      8
#define BROWSE_CD       9
#define COMPAT_LOCAL    10
#define COMPAT_TOOLS    11
#define VIEW_RELNOTES   12
#define INSTALL_CLR     13
#define MAX_OPTIONS     14
 
#define SCREEN_MAIN     0
#define SCREEN_TOOLS    1
#define SCREEN_COMPAT   2
 
extern const int c_aiMain[]; // menu string resources
extern const int c_cMain;    // counter of items in array
extern const int c_aiWhistler[];
extern const int c_cWhistler;
extern const int c_aiSupport[];
extern const int c_cSupport;
extern const int c_aiCompat[];
extern const int c_cCompat;

Download this source code here: https://securitronlinux.com/arma3/applets.zip. I have included the taskmanager, grpconv, and also the Control Panel source code.

1
2
3
4
5
6
7
8
9
10
DIRS    = \
          autorun     \
          cleanup     \
          control     \
          grpconv     \
          taskmgr     \
          tourstart   \
          upgrade
 
OPTIONAL_DIRS=

This is a sample of the source code from the Control Panel in Windows XP.

control\init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
#include "control.h"
#include <cpl.h>
#include <cplp.h>
#include <shlwapi.h>
#include <shlwapip.h>
#include "rcids.h"
 
BOOL ImmDisableIME(DWORD dwThreadId);
 
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//  LEAVE THESE IN ENGLISH
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
const TCHAR c_szCtlPanelClass[] = TEXT("CtlPanelClass");
const TCHAR c_szExplorer[] = TEXT("explorer.exe");
const TCHAR c_szRunDLL32[] = TEXT("rundll32.exe");
const TCHAR c_szRunDLLShell32Etc[] = TEXT("Shell32.dll,Control_RunDLL ");
const TCHAR c_szControlPanelFolder[] = 
    TEXT("\"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\"");
const TCHAR c_szDoPrinters[] = 
    TEXT("\"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}\"");
const TCHAR c_szDoFonts[] = 
    TEXT("\"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{D20EA4E1-3957-11d2-A40B-0C5020524152}\"");
const TCHAR c_szDoAdminTools[] = 
    TEXT("\"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{D20EA4E1-3957-11d2-A40B-0C5020524153}\"");
const TCHAR c_szDoSchedTasks[] = 
    TEXT("\"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}\"");
const TCHAR c_szDoNetConnections[] = 
    TEXT("\"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\"");
const TCHAR c_szDoNetplwizUsers[] = 
    TEXT("netplwiz.dll,UsersRunDll");    
const TCHAR c_szDoFolderOptions[] = 
    TEXT("shell32.dll,Options_RunDLL 0");    
const TCHAR c_szDoScannerCamera[] = 
    TEXT("\"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{E211B736-43FD-11D1-9EFB-0000F8757FCD}\"");
 
typedef struct
{
    LPCTSTR szOldForm;
    DWORD   dwOS;
    LPCTSTR szFile;
    LPCTSTR szParameters;
} COMPATCPL;
 
#define OS_ANY          ((DWORD)-1)
 
COMPATCPL const c_aCompatCpls[] =
{
    {   TEXT("DESKTOP"),          OS_ANY,               TEXT("desk.cpl"),       NULL                  },
    {   TEXT("COLOR"),            OS_ANY,               TEXT("desk.cpl"),       TEXT(",2")            },
    {   TEXT("DATE/TIME"),        OS_ANY,               TEXT("timedate.cpl"),   NULL                  },
    {   TEXT("PORTS"),            OS_ANY,               TEXT("sysdm.cpl"),      TEXT(",1")            },
    {   TEXT("INTERNATIONAL"),    OS_ANY,               TEXT("intl.cpl"),       NULL                  },
    {   TEXT("MOUSE"),            OS_ANY,               TEXT("main.cpl"),       NULL                  },
    {   TEXT("KEYBOARD"),         OS_ANY,               TEXT("main.cpl"),       TEXT("@1")            },
    {   TEXT("NETWARE"),          OS_ANY,               TEXT("nwc.cpl"),        NULL                  },
    {   TEXT("TELEPHONY"),        OS_ANY,               TEXT("telephon.cpl"),   NULL                  },
    {   TEXT("INFRARED"),         OS_ANY,               TEXT("irprops.cpl"),    NULL                  },
    {   TEXT("USERPASSWORDS"),    OS_ANYSERVER,         TEXT("lusrmgr.msc"),    NULL                  },
    {   TEXT("USERPASSWORDS"),    OS_WHISTLERORGREATER, TEXT("nusrmgr.cpl"),    NULL                  },
    {   TEXT("USERPASSWORDS2"),   OS_ANY,               c_szRunDLL32,           c_szDoNetplwizUsers   },
    {   TEXT("PRINTERS"),         OS_ANY,               c_szExplorer,           c_szDoPrinters        },
    {   TEXT("FONTS"),            OS_ANY,               c_szExplorer,           c_szDoFonts           },
    {   TEXT("ADMINTOOLS"),       OS_ANY,               c_szExplorer,           c_szDoAdminTools      },
    {   TEXT("SCHEDTASKS"),       OS_ANY,               c_szExplorer,           c_szDoSchedTasks      },
    {   TEXT("NETCONNECTIONS"),   OS_ANY,               c_szExplorer,           c_szDoNetConnections  },
    {   TEXT("FOLDERS"),          OS_ANY,               c_szRunDLL32,           c_szDoFolderOptions   },
    {   TEXT("SCANNERCAMERA"),    OS_ANY,               c_szExplorer,           c_szDoScannerCamera   },
    {   TEXT("STICPL.CPL"),       OS_ANY,               c_szExplorer,           c_szDoScannerCamera   },
};
 
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

It is so interesting to see how Windows XP works under the hood. It is not even complicated source code. Just loading various *.CPL files to enable functionality in the Control Panel.

Finally, this is the Makefile for the Control Panel source code.

control\makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#//----------------------------------------------------------------------------
#// Build the stub control panel
#//----------------------------------------------------------------------------
 
!ifdef NTMAKEENV
 
#
# Build using BUILD.EXE (Do not edit this section of this file, edit SOURCES)
#
!INCLUDE $(NTMAKEENV)\makefile.def
 
!else # NTMAKEENV
 
NAME=control
ROOT=..\..\..\..
RES_DIR=..
# // The 16bit version will be smaller and faster.
# // WIN32=TRUE	
# // DEFENTRY = ModuleEntry@0
 
!ifdef VERDIR
ROOT=..\$(ROOT)
!endif
 
PCHOBJ0=init.obj 
 
 
!ifdef WIN32
!if "$(VERDIR)" == "debug"
#// Debug needs comctl32 only for DebugMsg()
LIB0=kernel32.lib user32.lib comctl32.lib
!else
LIB0=kernel32.lib user32.lib
!endif
!else
!if "$(VERDIR)" == "debug"
#// Debug needs commctrl only for DebugMsg()
LIB0=libw mnocrtw commctrl
!else
LIB0=libw mnocrtw
!endif
!endif
 
!include $(ROOT)\win\core\shell\common.mk
 
!ifdef VERDIR
$(PRIVINC).pch pch.obj:	 $(ROOT)\dev\inc16\shell.h
 
$(NAME).res:	$(SRCDIR)\$(NAME).ico
 
!endif
 
!endif # NTMAKEENV

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.