KMK
KMK
驱动大牛
驱动大牛
  • 注册日期2001-09-12
  • 最后登录2017-10-06
  • 粉丝2
  • 关注0
  • 积分42分
  • 威望404点
  • 贡献值2点
  • 好评度58点
  • 原创分1分
  • 专家分1分
  • 社区居民
阅读:6857回复:5

Microsoft DDK mirror driver demystified

楼主#
更多 发布于:2009-11-17 15:24
 Microsoft DDK mirror driver demystified

Many people asking question on how to make mirror driver working.
As information was limited on this topic, I wrote this for my record and present here so people can learn how.

Mirror sample consist of three part
1.    User application     xxx.exe
2.    Display driver        xxx.dll        
3.    Miniport driver        xxx.sys

You can compile the sample with batch file below since I am not using Visual studio.

@echo off
C:\Windows\system32\cmd.exe /C
call C:\WinDDK\6001.17121\bin\setenv.bat C:\WinDDK\6001.17121\ chk WXP
cd\
cd C:\008\mirrortest\dll        <-- where source file located
build -ceZ
pause
exit

For me, need to add below line to make it error free in “sources” file for display driver.
TARGETLIBS=$(TARGETLIBS) $(SDK_LIB_PATH)\libcntpr.lib
“libcntpr.lib” was the only library that you can link with for video driver, if you linking with other library, your driver may not work!

And I need to change DDI_DRIVER_VERSION to DDI_DRIVER_VERSION_NT4 in enable.c
Those are the lines I need to modify, all other remain the same.
User application in DDK was suck; go to below page and copy the code
http://topic.csdn.net/t/20050114/11/3725191.html
then uncomment below
//   CreateMyWindow("Mirror   Sample");




Change code below
          case   WM_PAINT:  
                  DoubleBufPrint(hwnd);
                  //DoPaint(hwnd);  
                  break;  

code for DoubleBufPrint() below

int DoubleBufPrint(HWND hwnd)    // double-buffering
{
    HDC            hdcMem;
    HBITMAP        hbmMem;
    HANDLE        hOld;
    BITMAP        bmp;
    PAINTSTRUCT  ps;
    HDC          hdc, hdcf, hdcs;
    
    // Get DC for window
    hdc = BeginPaint(hwnd, &ps);
//-------------------------------------------------------------------------------    
    // screen capture from 0,0
    //hdcs = CreateDC("DISPLAY", NULL, NULL, NULL);        
//-------------------------------------------------------------------------------    
    // mirror region
    hdcs = CreateDC("DISPLAY", "\\\\.\\DISPLAYV1", NULL, NULL);    
//-------------------------------------------------------------------------------    
 // Create an off-screen DC for double-buffering
    hdcMem = CreateCompatibleDC(hdcs);
    hbmMem = CreateCompatibleBitmap(hdcs,
                        GetDeviceCaps(hdcs, HORZRES),
                        GetDeviceCaps(hdcs, VERTRES));

    GetObject(hbmMem, sizeof(BITMAP), &bmp);        // <-- for bmp.bmWidth, bmp.bmHeight

    // Draw into hdcMem
    BitBlt(hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcs, 0, 0, SRCCOPY);    
    // Transfer the off-screen DC to the screen
    BitBlt(hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);    

    // Free-up the off-screen DC
    DeleteObject(hbmMem);
    DeleteDC    (hdcMem);
    DeleteDC    (hdcs);
    
    EndPaint(hwnd, &ps);
    return 0;
}    


Two lines worth to explain
1.    hdcs = CreateDC("DISPLAY", NULL, NULL, NULL);
2.    hdcs = CreateDC("DISPLAY", "\\\\.\\DISPLAYV1", NULL, NULL);
First line got the DC from current display where second line got DC from mirror display

Device name “\\\\.\\DISPLAYV1 “  was taken from

&dispDevice.DeviceName[0] in the code and you may need to change it if necessary.
Last add a message loop between below two lines
                  
                  RegCloseKey(hKeyDevice);  
 // put message loop here
                  printf("Performed   bit   blit.     Finished.   \n");

//message loop

                       MSG msg;

                        while(GetMessage(&msg, NULL, 0, 0))
                        {
                            TranslateMessage(&msg);
                            DispatchMessage(&msg);
                        }    

If you don’t add the loop, you would not see the new created windows.

The start location and size of window create can adjust in CreateWindow() accordingly.
You may need to tweak it for better result.

Compile all files and install thru Device manager, this code still having some bug to fix but it enough for demonstration.

It works on my 333Mhz old XP machine and under XP on VMware.

Here is only show how to start with mirror driver, still having some direction to explore.
附件名称/大小 下载次数 最后更新
Mirror driver demystified.pdf (262KB)  121 2009-11-17 15:24
yeti1234
驱动牛犊
驱动牛犊
  • 注册日期2009-11-23
  • 最后登录2009-11-23
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望11点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2009-11-23 10:15
看到这篇文章太高兴了!!
abesysu
驱动牛犊
驱动牛犊
  • 注册日期2009-11-11
  • 最后登录2009-12-09
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望51点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2009-11-23 22:37
thank you!!!!
vknight
驱动牛犊
驱动牛犊
  • 注册日期2008-12-26
  • 最后登录2009-12-07
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望11点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2009-11-30 02:42
thanks!!!
sgua
驱动牛犊
驱动牛犊
  • 注册日期2005-10-28
  • 最后登录2009-12-22
  • 粉丝0
  • 关注0
  • 积分3分
  • 威望31点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2009-12-10 22:24
thank you very much
fengrucilianxue
驱动牛犊
驱动牛犊
  • 注册日期2015-06-10
  • 最后登录2015-06-10
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望11点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2015-06-10 10:18
附件不存在?什么情况啊
游客

返回顶部