Title: ppt title
1(No Transcript)
2How to play well with Windows XP Mike
BurrowsCode Monkey Windows 3rd Party Gaming
Group Microsoft Corporation
3Agenda
- What is Windows XP
- Whats new
- Handling Multiple Users
- Where to put your data
- How to work better on Windows XP
- Common application compatibility issues
4What is Windows XP?
- The OS formerly known as Whistler?
- Based on the Windows NT kernel?
- The biggest OS release sinceWindows 95?
- The most reliable, easiest to use, operating
system for retail consumers? - The best development platform?
- All of the above?
5Windows Roadmap to date
6Available versions
- Home Edition
- For general home user
- Professional
- For hardcore gamers and developers
- Server
- File/Print services, DCs, AD servers
- Advanced Server
- Web sites, B2B app. servers
- Datacenter
- High availability, mission critical applications
7Differences between versions
- Professional is superset of Home
- Adds
- Multi-processor support
- Remote desktop (Terminal Services)
- Encrypted file system
- Domain join
- Credential Manager
-
- NB. Home Edition has multi-mon
- Previous to RC1 it did not
8Agenda
- What is Windows XP
- Whats new
- Handling Multiple Users
- Where to put your data
- How to work better on Windows XP
- Common application compatibility issues
9Whats new?
- Absolutely loads of stuff, but most relevant
- DirectX 8.1
- Ships with Windows XP
- Redist for Windows 98, Windows ME and Windows
2000 happens 1 month after Windows XP RTMs - Multiple users by default
- Fast User Switching
- Much, much, much more similar to Windows 2000
than Windows 95 - Security implications
- New, task-oriented, Shell UI
10Agenda
- What is Windows XP
- Whats new
- Handling Multiple Users
- Where to put your data
- How to work better on Windows XP
- Common application compatibility issues
11Multiple Users
- Over 80 share a computer with other family
members - Two (36), Three (18), Four (15)
- Five and above (11)
- Yet most users arent enabling profiles
- People arent getting a personalized experience
- They cant switch easily between e-mail
accounts, etc. - Alternative solutions like Internet Explorer
Identities had to be put in place
12Multiple UsersWhy are people not using Profiles?
- Users dont know they can do this
- Windows 98 Profiles are off by default and are
hard to use - Switching users takes too much time and effort
(designed for Business) - Takes several minutes
- Must close your programs, log off, restart all
your programs - Have to type in user name andpassword hassle!
13Multiple UsersHow are we fixing this?
- Turning on Profiles by default
- User accounts will be created for everyone
- By default, passwords will not be required
- New, much easier, Control Panel to add/edit User
Accounts - Enabling Fast User Switching
- Multiple users can be running programs at the
same time - Disabled if connected to domain
14(No Transcript)
15(No Transcript)
16Multiple UsersHandling Lost Devices
- Return Code from Present() and Reset()
- D3DERR_DEVICELOST
- HRESULT hRes g_pD3ddev-gtPresent(NULL, NULL,
NULL, NULL) - while(hRes D3DERR_DEVICELOST)
-
- while(hRes ! D3DERR_DEVICENOTRESET)
-
- Sleep(1000)
- hRes g_pD3ddev-gtTestCooperativeLevel()
-
- hRes g_pD3ddev-gtReset(d3dpp)
- if(FAILED(hRes))
- hRes D3DERR_DEVICELOST
-
17Multiple UsersBe a good citizen
- When your application is not active on the
current desktop - Minimize processor usage
- Dont update display
- Dont play sounds
18Multiple UsersOther instances
- Check for other instances correctly
- FindWindow(Ex) does not work across sessions
- Do use it to check if the instance is in this
session if one found globally - Events, semaphores, mutexes, waitable timers,
file-mapping objects, etc - Dont just switch to the previous instance, it
may be in another session
19Multiple UsersCheck for other instances
- BOOL DoIExist(LPWSTR wzMutexName)
- HANDLE g_hMutexAppIsRunningg_hMutexAppIsRunnin
g CreateMutex(NULL, FALSE, wzMutexName) - // Return TRUE if existing semaphore opened
- if (g_hMutexAppIsRunning ! NULL
- GetLastError() ERROR_ALREADY_EXISTS)
- CloseHandle(g_hMutexAppIsRunning)return TRUE
-
- // wasnt found, new one created therefore return
FALSE - return (g_hMutexAppIsRunningNULL)
20Multiple UsersSwitch to other instance?
- WinMain()
-
- if ( DoIExist(L"Global\\KillerMonkeysFromMars")
TRUE ) -
- // Game found running. If its in this
session restore it - HWND hWndMe FindWindow(wzWindowClass,
wzTitle) - if (hWndMe)
-
- if (IsIconic(hWndMe))
-
- ShowWindow(hWndMe, SW_RESTORE)
-
- SetForegroundWindow(hWndMe)
-
- else
- MessageBox(NULL, L"Another User is using
Application", - wzTitle, MB_OK)
21Multiple UsersFast User Switching
- WTSRegisterSessionNotification()
- Notification of sessions connecting and
disconnecting, both local and remote - No way to stop session switch from occurring
- By the time you get the message the event will
probably have happened! - Ensure that everything is cleared up when leaving
desktop session if you cannot when entering new
session
22Multiple UsersFast User Switching
- Full-screen DirectDraw and Direct3D Titles will
not allow Fast User Switching - User can still task-switch then FUS though
- Also user can remote connect to desktop and pull
away other users desktop session - Two methods to handle this
- 1) Just hope everything sort of works
- 2) Deal with it using the WTSRegisterSessionN
otification( ) API - I recommend option 2 ?
23Multiple UsersFast User Switching
- BOOL WINAPI WTSRegisterSessionNotification(
- HWND hWnd, // Your Window handle
- DWORD dwFlags // Flags )
- Flags
- NOTIFY_FOR_THIS_SESSION
- Notified only about the session change events
that affect the session to which window belongs. - NOTIFY_FOR_ALL_SESSIONS
- Notified for all session change events.
24Multiple UsersFast User Switching
- wParam contains the action happening on the
session - May contain one of the following
- WTS_CONSOLE_CONNECT
- WTS_CONSOLE_DISCONNECT
- WTS_REMOTE_CONNECT
- WTS_REMOTE_DISCONNECT
- WTS_SESSION_LOGON
- WTS_SESSION_LOGOFF
- WTS_SESSION_LOCK
- WTS_SESSION_UNLOCK
- lParam contains the sessionId for the session
affected.
25Multiple UsersFast User Switching
- Register your HWND to receive a
WM_WTSSESSION_CHANGE message - Use NOTIFY_FOR_THIS_SESSION flag unless you know
better - Signifies that you only care about events that
affect your session - May have to take drastic action when certain
messages are received - e.g., WTS_REMOTE_
- MAY need to terminate app
- Not always...
- HWND values passed are ref counted so remember on
app exit to call WTSUnRegisterSessionNotification(
)
26Agenda
- What is Windows XP
- Whats new
- Handling Multiple Users
- Where to put your data
- How to work better on Windows XP
- Common application compatibility issues
27Data Storage LocationsSecurity Issues
- NTFS formatted drives expected to be default for
OEM installs - Much larger hard drive sizes in new PCs
- Security restrictions for limited uses cannot be
bypassed - Limited users have NO write access to
- HKEY_LOCAL_MACHINE registry branch
- ALL of the hard drive with exception of
- All User and Current User My Documents
- All User and Current User Application Data
- VERY important to follow these rules on where to
put data - Otherwise expect many Access Denied scenarios for
Limited Users
28Data Storage LocationsHard Coded Paths
- A lot of folders have moved around
- Windows 9x
- \My Documents
- Windows NT 4.0
- windir\profiles\mikebur\personal
- Windows 2000/XP
- \Documents and Settings\mikebur\My Documents
- Use SHGetFolderPath on
- Windows 95/98/Windows NT 4.0/2000 as well as
Windows XP
29Data Storage LocationsWhere to install the game
- Install for All Users by default
- User installing should have Admin privileges
- Install by default to the Program Files folder
- This is not always C\Program Files !
- Use SHGetFolderPath( ) with CSIDL_PROGRAM_FILES
30Data Storage LocationsThings to STOP doing in
the install
- Putting files in the Windows directory or any of
its subdirectories - Putting runtime generated data in program
directory or a subdirectory - This will cause your app to fail for limited
users - Installing icons on to desktop by default
- Installing icons on to the system tray
31Data Storage LocationsSHGetFolderPath( ) API
- Redistributable on Windows 95 and Windows NT 4.0
- SHFOLDER.EXE in Platform SDK
- mssdk\redist\shfolder\shfolder.exe
- Always specify CSIDL_FLAG_CREATE
- Will create folders if needed on 9x
32Data Storage LocationsSHGetFolderPath( ) API
Common CSIDL defines
- Learn these, all will work on Windows 9x too
- After shfolder redist installed
33Data Storage LocationsWhere to put application
generated data files
- If user is NOT meant to load / view / alter data
- If data is per machine, e.g., system config
- CSIDL_COMMON_ APPDATA
- If data is per user, e.g., keyboard bindings
- CSIDL_LOCAL_APPDATA
34Data Storage LocationsWhere to put application
generated data files
- If user IS meant to load / view / alter it
- Ensure there is a file association to the app
- See sample code for way to do this within your
installer - Alternatively use commercial installer
- If data is for any user to use, e.g., shared
hiscores - CSIDL_COMMON_DOCUMENTS
- If data is only for current user, e.g., private
hiscore - CSIDL_PERSONAL
35Data Storage LocationsExample Code generated
data per user
- Store saved game in
- C\Documents and Settings\ltusernamegt\My
Documents\Games directory - TCHAR szPathMAX_PATH
- if(SUCCEEDED (SHGetFolderPath(NULL,
CSIDL_PERSONALCSIDL_FLAG_CREATE, NULL, O,
szPath)) -
- PathAppend(szPath, T(Games\\Saved1.killermonkey
frommars")) - HANDLE hFile CreateFile(szPath,...)
-
36Data Storage LocationsExample Code for generated
data per machine
- Store game configuration file in
- C\Documents and Settings\All Users \Application
Data\ltpublishergt\ltgamegt directory - TCHAR szPathMAX_PATH
- if(SUCCEEDED (SHGetFolderPath(NULL,
CSIDL_COMMON_APPDATACSIDL_FLAG_CREATE, NULL,
O, szPath)) -
- PathAppend(szPath, T(Publisher\\killermonkeyfro
mmars\\config.dat")) - HANDLE hFile CreateFile(szPath,...)
-
37Data Storage LocationsCreating file association
with shell
- Based on info from MSDN at
- http//msdn.microsoft.com/library/default.asp?url
/library/en-us/shellcc/shellcc/shell/Shell_basics/
FileAssoc.asp - Setting the file type key to the name of the exe
is not enough - Subkeys about the shell method are also required
- Resultant hierarchy should be
- HKEY_CLASSES_ROOT.foo FooFileFooFile
shell open
command FooApp.exe 1
38Data Storage LocationsExample Code for creating
file association
- include ltwindows.hgt
- include ltshlobj.hgt
- include ltstdio.hgt
- const char g_szFileExtension ".foo"
- const char g_szFileType "FooFile"
- const char g_szFileDesc "Foo Test File"
- // Simple app which registers a file association
with the shell - // If invoked with no command line parameters, it
tests to see - // if the reg key for the file extension already
exists, if not it - // creates it and associates it with the file
type, then defines - // the shell/open method for that file type to
launch this app with - // a command line parameter of the file name
being launched. - // based on information at
- //
39Data Storage LocationsExample Code for creating
file association
- int main( int argc , char argv )
-
- // Do we have a command line parameter?
- if ( argc gt 1 )
-
- // Yup, so hopefully this is because we were
launched by - // the shell because of a file association
- char strMAX_PATH2
- sprintf( str, "Launched with param s", argv1
) - MessageBox( NULL, str, "File Association",
MB_OK ) - return 0
-
- // No command line, so we should just register
our file type - // Get full path to this EXE
- char app_pathMAX_PATH
- GetModuleFileName( NULL, app_path, MAX_PATH )
40Data Storage LocationsExample Code for creating
file association
- // Attempt to open our extension key // under
HKEY_CLASSES_ROOT - HKEY hkey
- DWORD disp
- LONG rc
- rc RegOpenKeyEx( HKEY_CLASSES_ROOT,
g_szFileExtension,
0, KEY_READ, hkey ) - RegCloseKey( hkey )
- // If we succeeded, then key already exists we
are done - if ( ERROR_SUCCESS rc )
-
- return 0
-
41Data Storage LocationsExample Code for creating
file association
- // Key does not exist, so attempt to create it
- rc RegCreateKeyEx( HKEY_CLASSES_ROOT,
g_szFileExtension, 0, NULL, 0,
KEY_SET_VALUE, NULL, hkey, disp ) - if ( rc ! ERROR_SUCCESS )
-
- printf( "Unable to create reg key\n" )
- return -1
-
- // Created key for file extension, so now set//
value to our file type and close key - rc RegSetValueEx( hkey, NULL, 0, REG_SZ,
(BYTE)g_szFileType ,
strlen(g_szFileType) ) - RegCloseKey( hkey )
- if ( rc ! ERROR_SUCCESS )
-
- printf( "Unable to set reg key\n" )
- return -1
-
42Data Storage LocationsExample Code for creating
file association
- // Now create a key for the file type
- rc RegCreateKeyEx( HKEY_CLASSES_ROOT,
g_szFileType, 0, NULL, 0,
KEY_SET_VALUEKEY_CREATE_SUB_KEY, NULL,
hkey , disp ) - if ( rc ! ERROR_SUCCESS )
-
- printf( "Unable to create reg key\n" )
- return -1
-
- // Created key for file type, set value to file
descrip. - rc RegSetValueEx( hkey, NULL, 0, REG_SZ,
(BYTE)g_szFileDesc, strlen(g_szFileDesc) )
43Data Storage LocationsExample Code for creating
file association
- // Create sub key for shell
- HKEY shellkey
- rc RegCreateKeyEx( hkey, "shell", 0, NULL, 0,
KEY_SET_VALUE KEY_CREATE_SUB_KEY,
NULL,
shellkey , disp ) - // Create sub key for "open"
- HKEY openkey
- rc RegCreateKeyEx( shellkey, "open", 0, NULL,
0, KEY_SET_VALUE
KEY_CREATE_SUB_KEY, NULL,
openkey , disp ) - // Create sub key for "command"
- HKEY commandkey
- rc RegCreateKeyEx( openkey, "command", 0,
NULL, 0,
KEY_SET_VALUE , NULL ,
commandkey , disp ) - // Set value of "command" key to be our app path
"1 - // the first command-line parameter, the
filename - strcat( app_path , " 1" )
- rc RegSetValueEx( commandkey, NULL, 0,
REG_EXPAND_SZ,
(BYTE)app_path, strlen(app_path) )
44Data Storage LocationsExample Code for creating
file association
- // Close all the keys
- RegCloseKey( commandkey )
- RegCloseKey( openkey )
- RegCloseKey( shellkey )
- RegCloseKey( hkey )
- // Notify shell of the change
- SHChangeNotify( SHCNE_ASSOCCHANGED,
SHCNF_IDLIST, 0, 0 ) - // Done
- printf( "Registered file extension s\n",
g_szFileExtension
) - return 0
45Agenda
- What is Windows XP
- Whats new
- Handling Multiple Users
- Where to put your data
- How to work better on Windows XP
- Common application compatibility issues
46Work better with Windows XPUsing Virtual
functions to help find bugs
- VirtualAlloc( )
- MEM_RESERVE
- Reserves a region in your address space
- Does not commit physical storage
- MEM_COMMIT
- Commits physical storage
- Can combine with MEM_RESERVE
- Specify a page protection attribute
- Automatically rounds to page boundary
- Free up with VirtualFree( )
47Work better with Windows XPUsing Virtual
functions to help find bugs
- VirtualProtect( )
- Changes page protection attributes
- Works on committed pages only
- Useful to set some data to READONLY
- System can make optimisations
- Helps track down bugs
- e.g., build a data structure during
initialization, which you then subsequently only
want to read from, you could change the attribute
of the page to READONLY once youve done the
init. Then any errant writes to the data
structure will immediately cause a fault which
you can trap in the debugger.
48Work better with Windows XPPerformance Tips
File I/O
- Avoid opening and closing files frequently
- Opening a file can be a costly operation
- Added security in Windows NT means this operation
uses more resources - Keep a file open. Only close it when youre done
- Dont keep opening and closing the same file
- Some legacy code does this to help out old OSs
(e.g., MS-DOS) which imposed arbitrary limits on
the number simultaneously open files. Such limits
no longer exist.
49Work better with Windows XPPerformance Tips
File I/O
- Give the system information about your usage
patterns - Use FILE_SCAN_SEQUENTIAL flag in CreateFile( )
call - Optimizes access when you read through a file
from start to finish - OS will read-ahead of your accesses
- Most games could use this
- Organise your data in order required
- Particularly if reading from CD or DVD
50Work better with Windows XPPerformance Tips
Lowering Memory Usage
- Dont statically link to the C runtime library
- Use Win32 functions instead where possible,
since the system DLLs will be mapped into your
process address space anyway - Instead of C runtime library, use routines
exported by NTDLL - Zero hit as NTDLL is always in address space of
every process - Avoid using LIBC.LIB or LIBCMT.LIB
51Work better with Windows XPPerformance Tips
Decreasing load times
- Use LoadLibrary() to control DLL loading
- Gives you control over when DLLs get loaded
- C function pointer syntax means your code can
look the same - Allows your app to start up quicker
52Work better with Windows XPPerformance Tips
Removing needless page ins
- Call DisableThreadLibraryCalls()
- Usually DLLMain gets called with
DLL_THREAD_ATTACH for each new thread in a
process - Most DLLs dont use this information
- Could just return straight away from DLLMain in
this case, but by that time the code has already
been paged in - Calling DisableThreadLibraryCalls() prevents the
system making the call in the first place
53Work better with Windows XPPerformance Tips
Improving paging
- Declare constant variables as const
- Compiler could omit variable altogether
- Will be placed in read only section
- Improves paging characteristics, since read/write
pages will be more densely packed with genuine
read/write data
54Work better with Windows XPPerformance Tips
Better memory usage
- Statically initialize DLL global variables once
- Use well-behaved data structures that arent
spread across many pages - Private heaps can help, but be careful!
- Test many design policies before deciding
55Work better with Windows XPPerformance Tips
Memory access patterns
- Memory may not be random-access
- e.g., write DWORD to 2 megabytes of paged memory
(4k pages) - Best case 512 page faults, written serially
- Worst case 1,000,000 page faults (1024
squared) - Assume each page fault takes 10 milliseconds
- Best case 5 seconds (512 10ms)
- Worst case 2.75 hours (1,000,000 10ms
10,000 seconds)
56Work better with Windows XPWorking with NATs is
Critical
- Many firewalls are based on NAT
- With 24x7 connectivity of personal firewalls
deployed will increase - Windows ICS is widely deployed
- Lots of other NATs from lots of vendors
- Cable DSL modems
- ISDN routers
- Other combo router/gateway/edge devices
- Forcing NAT to edit protocols does not scale with
either the of protocols or the of NAT
solutions - DirectPlay 8 has full NAT support
57Agenda
- What is Windows XP
- Whats new
- Handling Multiple Users
- Where to put your data
- How to work better on Windows XP
- Common application compatibility issues
58Windows XP CompatibilityCommon scenarios
- Really application incapabilities
- What makes an application incompatible?
- It doesnt install
- The operating system changed functionality
- A change in the operating system has exposed a
bug in the application - Platform differences
59Windows XP CompatibilitySetup And Installation
- Most common problem?
- Application wont install
- The most common reason for not installing is
Windows is bad version checking - Operating system upgrade has higher application
pass rates than clean installs
60Windows XP CompatibilityWin32 API Changes
- WM_KEYUP and WM_KEYDOWN
- Pass the whole of wParam to TranslateMessage
- GetWindowsDirectory
- Returns a per-user windows directory
- OPENFILENAME STRUCTURE
- lpstrInitialDir may lead to personal directory
- DS_SHELLFONT
- System uses "MS Shell Dlg 2"
61Windows XP CompatibilityCommon Heap Issues
- Access memory after freed
- Allocate -gt Write/Read -gt Free -gt Read
- Can corrupt data
- May not cause a Access Violation
- Windows 2000 and Windows XP reuse blocks faster
- Re-allocate to smaller block
- Windows may move a block
62Windows XP CompatibilityIncreased Stack
Consumption By System Code
- System uses more stack space
- Applications that are allocating small stacks may
crash - Check for and remove (preferably) or fix
- /STACK linker option
- STACKSIZE - .DEF file
- /F compiler option
63Windows XP CompatibilityCalling Conventions
- Use STDCALL for all Window procedures
- Windows and dialogs
- Using C_DECL on Windows 95/98 will still work
- Wont work well on Windows XP
- Make sure the implementation of the calling
convention properly preserves registers
64Windows XP CompatibilityOrder Of Messages
- Dont depend on Windows messages being delivered
in any particular order - New thread scheduler exposes bugs
- Messages are not a synchronization object in
Windows - Use the Win32 synchronization objects for this
65Windows XP CompatibilityMicrosoft Technologies
That Can Help You
- Extensible/Updateable AppCompat Database
- AppsHelp
- Compatibility Fixes
- Compatibility Layers
- Compatibility Mode Wizard
- AppCompat Toolkit
66Windows XP CompatibilityHow we can help existing
titles be compatible
- Having working Windows 9x titles is a priority
- Variety of options available to fix your existing
titles - AppsHelp feature
- Helps a customer avoid running known problem
applications - Can point to a location where updates or more
information is available - Microsoft can update with your help through
Windows Update, Service Packs
67Windows XP CompatibilityHow we can help existing
titles be compatible
- AppFixes
- Best customer experience short of a patched
application or new version - Ultra-specific way to fix up games expecting
certain Windows 9x API behaviors - Updated through Windows Update or Service Packs
only - If title cannot be fixed and can cause system
instability then it will be blocked from running
to prevent system damage
68Windows XP CompatibilityCompatibility Fixes
Technology
- Allows us to dynamically fix applications that
have already shipped - Ultra-specific way to address differences in API
behaviors between Windows versions - Designed to be lightweight with minimal side
effects
69Windows XP CompatibilityCompatibility Layers and
Wizard
- Compatibility Layers
- Collections of specific compatibility fixes
designed to mimic behavior of previous versions
of Windows - Compatibility Mode Wizard
- Walks user through applying a Compatibility Layer
to an application - Ability to make persistent so the application
will always be run with that with layer
70Windows XP CompatibilityApplication
Compatibility Toolkit
- White papers Documents
- Lists Common Compatibility Issues
- Test checklist for finding problems in
applications - Testing procedure document for developing new
applications - Designed for Windows XP Application Specification
- Lots of useful pointers and tips for better
stability, including a dedicated Gaming Supplement
71Windows XP CompatibilityApplication
Compatibility Toolkit
- Utilities for Fixings apps
- QAppFix, AppParse, PageHeap, CompatAdmin.
- Dont depend on us using the utilities to fix
your forthcoming titles, you use them to - Identify problem area with any released titles
- Determine area of incompatibility in title in
development now to reduce time finding issues - Beta version available now for
- Windows XP
- Where can I get the toolkit?
- http//msdn.microsoft.com/compatibility
72SummaryThe best development platform
- All the benefits of Windows 2000
- More drivers available earlier
- Develop on the same platform as your customers
use - Terminal Services make remote debugging easier
- You dont have to have a developer system at
home to work at home.
73Call To Action!
- Contact any member of staff to get a copy of
Windows XP now! - Ensure you have Windows XP on some of your dev
machines - Ensure you have Windows XP Home AND Professional
on some of your configuration testing machines - Let us help test your titles before you ship
rather than try to fix them afterward - http//msdn.microsoft.com/directx
74Questions?
?
?
?
?
?
?
?
?
?
?
?