home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / device.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  2.5 KB  |  97 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : device.h                                                             //
  12. //  Description: Service Control Manager wrapper                                     //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. // Service Control Manager
  17. class KSCManager
  18. {
  19. public:
  20.  
  21.     SC_HANDLE m_schSCManager;
  22.  
  23.     KSCManager()
  24.     {
  25.         m_schSCManager = NULL;
  26.     }
  27.  
  28.     bool OpenSCM(void)
  29.     {
  30.         m_schSCManager = OpenSCManager (NULL, NULL, 
  31.             SC_MANAGER_ALL_ACCESS);
  32.  
  33.         return m_schSCManager != NULL; 
  34.     }
  35.  
  36.     bool CloseSCM(void)
  37.     {
  38.         if ( m_schSCManager )
  39.             return CloseServiceHandle(m_schSCManager) != 0;
  40.         else
  41.             return false;
  42.     }
  43. };
  44.  
  45.  
  46. // Device
  47. class KDevice : public KSCManager
  48. {
  49.     const TCHAR * m_DeviceName;
  50.     SC_HANDLE     m_schService;
  51.     HANDLE        m_hDevice;
  52.  
  53.     unsigned RemoveDriver(void);
  54.     
  55.     unsigned InstallDriver(const TCHAR * DriverExe);
  56.     unsigned StartDriver(void);
  57.     unsigned StopDriver(void);
  58.  
  59.     unsigned OpenDevice(void);
  60.     unsigned CloseDevice(void);
  61.  
  62. public:
  63.     
  64.     KDevice(LPCTSTR DeviceName)
  65.     {
  66.         m_DeviceName = DeviceName;
  67.         m_schService = NULL;
  68.         m_hDevice    = NULL;
  69.  
  70.         OpenSCM();
  71.     }
  72.  
  73.     ~KDevice()
  74.     {
  75.         if ( m_schService )
  76.             CloseServiceHandle( m_schService );
  77.  
  78.         CloseSCM();
  79.     }
  80.  
  81.     unsigned Load(const TCHAR * DriverExe);
  82.     unsigned Close(void);
  83.  
  84.     BOOL  IoControl(DWORD   dwIoControlCode, 
  85.                     LPVOID  lpInBuffer, 
  86.                     DWORD   nInBufferSize, 
  87.                     LPVOID  lpOutBuffer, 
  88.                     DWORD   nOutBufferSize, 
  89.                     LPDWORD lpBytesReturned) 
  90.     {
  91.         return DeviceIoControl(m_hDevice, dwIoControlCode,
  92.             lpInBuffer, nInBufferSize, lpOutBuffer, 
  93.             nOutBufferSize, lpBytesReturned, NULL);
  94.     }
  95. };
  96.  
  97.