home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_03 / TestPeriscope / TestPeriscope.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-30  |  3.0 KB  |  99 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : textperiscope.cpp                                                     //
  10. //  Description: Test program for periscope.sys kernel mode driver, Chapter 3        //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <winioctl.h>
  19. #include <assert.h>
  20. #include <tchar.h>
  21.  
  22. #include "device.h"
  23. #include "..\Periscope\\Periscope.h"
  24. #include "resource.h"
  25.  
  26. int MyMessageBox(HWND hWnd, const TCHAR * text, const TCHAR * caption, DWORD style)
  27. {
  28.     MSGBOXPARAMS param;
  29.  
  30.     memset(& param, 0, sizeof(param));
  31.     param.cbSize      = sizeof(param);
  32.     param.hwndOwner   = hWnd;
  33.     param.hInstance   = GetModuleHandle(NULL);
  34.     param.lpszText    = text;
  35.     param.lpszCaption = caption;
  36.     param.dwStyle     = style | MB_USERICON;
  37.     param.lpszIcon    = MAKEINTRESOURCE(IDI_GRAPH);
  38.  
  39.     return MessageBoxIndirect(¶m);
  40. }
  41.  
  42. class KPeriscopeClient : public KDevice
  43. {
  44. public:
  45.     KPeriscopeClient(const TCHAR * DeviceName) : KDevice(DeviceName)
  46.     {
  47.     }
  48.  
  49.     bool Read(void * dst, const void * src, unsigned len);
  50. };
  51.  
  52.  
  53. bool KPeriscopeClient::Read(void * dst, const void * src, unsigned len)
  54. {
  55.     unsigned      cmd[2] = { (unsigned) src, len };
  56.     unsigned long dwRead;
  57.    
  58.     return IoControl(IOCTL_PERISCOPE, cmd, sizeof(cmd), dst, len, &dwRead) && (dwRead==len);
  59. }
  60.  
  61.  
  62. void GetFullName(HINSTANCE hInstance, const TCHAR * module, TCHAR fullname[])
  63. {
  64.     GetModuleFileName(hInstance, fullname, MAX_PATH);
  65.  
  66.     TCHAR * pName = fullname;
  67.  
  68.     while ( _tcschr(pName, ':') || _tcschr(pName, '\\') )
  69.         if ( _tcschr(pName, ':') )
  70.             pName = _tcschr(pName, ':') + 1;
  71.         else
  72.             pName = _tcschr(pName, '\\') + 1;
  73.  
  74.     if ( pName )
  75.         _tcscpy(pName, module);
  76. }
  77.  
  78.  
  79. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
  80. {
  81.     KPeriscopeClient scope("PeriScope");
  82.  
  83.     TCHAR fullname[MAX_PATH];
  84.     GetFullName(hInst, "periscope.sys", fullname);
  85.     
  86.     if ( scope.Load(fullname)==ERROR_SUCCESS )
  87.     {
  88.         unsigned char buf[256];
  89.  
  90.         scope.Read(buf, (void *) 0xa000004E, sizeof(buf));
  91.         scope.Close();
  92.  
  93.         MyMessageBox(NULL, (char *) buf, "Mem[0xa000004e]", MB_OK);
  94.     }
  95.     else
  96.         MyMessageBox(NULL, fullname, "Unable to load kernel mode driver", MB_OK);
  97.  
  98.     return 0;
  99. }