阅读:7268回复:5
Microsoft DDK mirror driver demystified
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. |
|
|
沙发#
发布于:2009-11-23 10:15
看到这篇文章太高兴了!!
|
|
板凳#
发布于:2009-11-23 22:37
thank you!!!!
|
|
地板#
发布于:2009-11-30 02:42
thanks!!!
|
|
地下室#
发布于:2009-12-10 22:24
thank you very much
|
|
5楼#
发布于:2015-06-10 10:18
附件不存在?什么情况啊
|
|