Exercise 2: Solving UIPI Issues
Task 1 – Explore the Ping Pong Sample
In this task, you will investigate the Visual Studio solution to understand what the code does.
Double-click the PingPongBroken solution
Help
Visual Studio 2008 should start and load the solution. The solution contains four projects: two native and two managed. Each pair is the Ping Pong application itself and a convenient loader that starts one process with standard user privileges and the other with administrator privileges.
- Open the PingPong.cpp fileThe PingPongDlgProc function is the modal dialog procedure handling the bulk of the work. To coordinate properly, the RegisterWindowsMessage function is used to obtain a global (technically, globally to the process’ Windows Station) message id for inter-process communication. The resulting message, uMsgBall, is the one posted between windows of the two running processes.
- The WinMain function searches for another instance of the same executable by looking for the existence of another window with the same caption (using the FindWindow function)
A timer is used to wait 500 msec in between message passing
Task 2 – Fix the Code
The PostMessage function used for message passing fails if its intended message is to a window belonging to a process with a higher privilege level. However, we can use a message filter to let some messages through:
- After the message registers in the WM_INITDIALOG handler, use the ChangeWindowFilter function to let the registered message pass through, regardless of privilege levels.
Add a call to that function with the MSGFLT_ADD flag to add the message to the filter. The code should look like the following:uMsgBall = RegisterWindowMessage(sMessageBall);
if(!uMsgBall) return FALSE;
// allow our message to come in even if sent by lower privilege
// process
ChangeWindowMessageFilter(uMsgBall, MSGFLT_ADD);
- Build the project and test it with NativePingPongLoader.Exe. It should work as expected. The complete solution is in the PingPongFixed folder.