How to capture desktop change using mirror driver

Hello, everyone. I’m new to driver development, maybe my question is basic
and general.

I’ve compiled the mirror sample in WDK 7.1.0 successfully and it worked as
its doc says, but I still don’t know how to capture desktop change using the
this mirror mechanism. Could someone point me out or could someone give me a
piece of advice about that or tell me how the sample work in theory. Thank
you.

Hi Bob. Did you use the search function of this web site? You would have found things like this:

How to track changes in a mirror driver:
http://www.osronline.com/showThread.cfm?link=168247

Queries on mirror driver:
http://www.osronline.com/showThread.cfm?link=185634

Is there any way to detect only change regions on primary desktop:
http://www.osronline.com/showThread.cfm?link=186818

A rough outline:
A mirror driver maintains it’s own copy of the desktop. In DrvEnableSurface() the driver creates it’s “screen surface”. The drawing operations are handled by GDI or/and your mirror driver, depending on the type of surface (engine(GDI) managed, device managed) and on the hooks you have defined during the surface creation. If the driver created an engine-managed-suface with no hooks defined, GDI handles all the drawing (rendering) operation. To hook some or all rendering function calls, the driver specifies the hooks as flags of the flHook parameter of the EngAssociateSurface()/EngModifySurface() functions. Let’s say you have hooked some of the DrvXxx functions(e.g. DrvBitBlt). Every time the desktop changes, GDI calls on the one hand the driver of the physical graphics device and on the other hand the corresponding DrvXxx() function of your mirror driver. You can punt the call back to GDI (call the corresponding EngXxx() function) to let GDI render for you. The great thing is, that you have detailed information about the “changed area” of the desktop within the parameter list of the DrvXxx() call. The target-rectangle in combination with the clip region gives you that information.

Kind regards,
Markus

Thanks for your reply, Markus.
I’ve read some of threads you provide several times,but it seems the answers are not so close to the core area.
Anyway I’ll take your advice and dig deep,thanks!
BTW, I’ve read an excellent article on codeproject(http://www.codeproject.com/KB/system/driverdev6asp.aspx?fid=262328),
I followed the example and finally I successfully got it worked.
The driver in that article was about a virtual display driver, when the driver was loaded,
I could grab a window onto the display surface,
it just like a second desktop.After several days digging,
I thought I almost got the idea of how it works,but when I came to mirror driver in WDK,
I just got confused about the app module of the sample,was the mirror similar to the virtual driver?Is it another “a second desktop”?

regards,
bob

Hi Bob,

I know the codeproject-sample, it helped me to understand the basics of display drivers, too. :slight_smile:
If you study the code you can see, that the driver creates a device surface and then notifies GDI about the attributes of the surface (EngModifySurface). It defines the “pvScan0”-parameter to point to a memory mapped file. So, the GDI renders into this memory mapped file. The viewer-application also opens this memory mapped file and shows the content in the window. That is how the sample works in principle.

A mirror driver works similar to this virtual display driver. You have to create a surface onto which the drawing operations are done. If you maintain this surface and provide the memory for it, you are able to read the “content” of this surface as well. This memory can be a memory mapped file like in the codeproject-sample. Alternativly you can allocate a block of system memory (EngAllocMem) to provide memory for the bitmap bits.
A mirror driver does not extend your windows desktop like the codeproject-sample does. Rather, you can attach the mirror to the already existing windows desktop (or a part of it) and your mirror driver gets called every time this part of the desktop changes. The application of the mirror driver sample just attaches the mirror driver to the “primary display device”. In theory you can attach the mirror driver to any part of the windows desktop you want to mirror.

Regards,
Markus

Yeah, seems you’ve got a lot from the codeproject-sample, thanks for your rapid apply which is so much helpful.
First off, the codeproject-sample is indeed a good start for display driver devs. But when I test the sample on WinXP, there’re something strange. The driver won’t work unless I modify the display setting in the “Display-Settings” dialog on the second display driver, or the mapped file won’t be created.
Second, about the mirror. There’re four commands which the monitor-application accepts.
-e: attach the mirror to the primary desktop
-d: detach the mirror to the primary desktop
-t: when mirror is attached, the application does some GDI APIs callings to the mirror driver indirectly(But I never get any debug output from that driver, confusing…)
-w:Create a window, nothing but showing a blue background all the time, when I move some window in the primary desktop, the hooked-Drvxxx in dll driver get called. Seems the window is not monitoring the mirror driver’s display surface, I wonder why they pop up such a window while not display the change of the primary desktop in that window.
So that’s my understanding about the mirror.
Again, thanks for your sharing about mirror.

Regards,
Bob

What do you mean with “modify the display settings”?

When you start the application with -w the created window is not going to show the mirror driver’s surface. It has to do with “Tracking Window Changes”. Take a look at this:
http://msdn.microsoft.com/en-us/library/ff570093(VS.85).aspx

The -t parameter: I have never started the application with this parameter, but I think the corresponding DrvXxx() functions should get called.

As long as your mirror driver is loaded you should get a lot of debug messages in any case.
May be you have to check the value of “DebugLevel”? It is “0” by default, so all debug messages defined with a debug level >0 will not get print. Change the value of DebugLevel (debug.c) or change the code to DISPDBG((0, …).

Regards,
Markus

Hi, there.
First, the “modify the display settings”. On my virtual Win XP, when the
virtual display driver is loaded, to get it work actually, I open the
“Display->Settings” dialog, then you’ll find there’re two display adapters
in the preview dialog in the center. I select the virtual driver, and check
the “Extend desktop to this display” option below, then the mapping
file(video.dat) is created by the system finally. If I don’t check that
option, nothing create and the monitor-app won’t show anything as well.
Seems the “Extend desktop to this display” option start the driver. BTW, I
haven’t test it on win 2003 and win 7.
Then, the mirror sample. As you said, I’ll review the code to confirm the "
DebugLevel " issue. Anyway I guess I’ve got to do more research on it.
Thanks for your kind advice.

Regards,
Bob

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@beckhoff.com
Sent: Thursday, August 05, 2010 9:34 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to capture desktop change using mirror driver

What do you mean with “modify the display settings”?

When you start the application with -w the created window is not going to
show the mirror driver’s surface. It has to do with “Tracking Window
Changes”. Take a look at this:
http://msdn.microsoft.com/en-us/library/ff570093(VS.85).aspx

The -t parameter: I have never started the application with this parameter,
but I think the corresponding DrvXxx() functions should get called.

As long as your mirror driver is loaded you should get a lot of debug
messages in any case.
May be you have to check the value of “DebugLevel”? It is “0” by default, so
all debug messages defined with a debug level >0 will not get print. Change
the value of DebugLevel (debug.c) or change the code to DISPDBG((0, …).

Regards,
Markus


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer