home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_04 / Diver / Module.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  3.1 KB  |  106 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   : module.h                                                             //
  12. //  Description: KModuleTable                                                        //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. #define Copy(dest, src) { dest[sizeof(dest)-1] = 0; strncpy(dest, src, sizeof(dest)-1); }
  17.  
  18. class KInterface
  19. {        
  20.     FARPROC *pvtbl;
  21.  
  22. public:
  23.     
  24.     FARPROC GetFuncAddr(int id)
  25.     {
  26.         return pvtbl[id];
  27.     }
  28.  
  29.     BOOL Hack(int id, FARPROC newfunc);
  30. };
  31.  
  32. BOOL HackMethod(unsigned vtable, int id, FARPROC newfunc);
  33.  
  34.                         //--------    Module Table    --------//
  35.                         
  36. const int MAX_MODULENAME = 32;
  37. const int MAX_MODULE     = 32;                        
  38.  
  39. class KModule
  40. {
  41. public:
  42.     unsigned    m_vtable;
  43.     unsigned    m_queryinterface;
  44.     int            m_methodno;
  45.     
  46.     char        m_caller[MAX_MODULENAME];     // caller module name, eg: clock.exe
  47.     char        m_callee[MAX_MODULENAME];     // callee module name, eg: gdi32.dll 
  48.     char        m_intrfc[MAX_MODULENAME];      // interface name,     eg: IDirectDraw    
  49.     
  50.     HINSTANCE   m_handle;                     // module handle returned by LoadLibrary 
  51.  
  52.     BOOL m_isinterface(void) const
  53.     {
  54.         return m_intrfc[0] == 0;
  55.     }
  56. };
  57.  
  58.  
  59. class KModuleTable
  60. {
  61.     KModule       m_modules[MAX_MODULE];
  62.     int        m_moduleno;
  63.  
  64. public:        
  65.     int        m_lastmodule;
  66.  
  67.     const char *CalleeName(int id) const
  68.     {
  69.         return m_modules[id].m_callee;
  70.     }
  71.  
  72.     const char *CallerName(int id) const
  73.     {
  74.         return m_modules[id].m_caller;
  75.     }
  76.  
  77.     HINSTANCE ModHandle(int id) const
  78.     {
  79.         return m_modules[id].m_handle;
  80.     }
  81.  
  82.     BOOL IsInterface(int id) const
  83.     {
  84.         return m_modules[id].m_isinterface();
  85.     }
  86.  
  87.     unsigned VTable(int id) const
  88.     {
  89.         return m_modules[id].m_vtable;
  90.     }
  91.     
  92.     void Initialize(void)
  93.     {
  94.         m_moduleno = 0;
  95.     }
  96.     
  97.     int  LookupModule(const char *caller, const char *callee);
  98.     
  99.     int  LoadModule(const char *caller, const char *callee, const char * intrfc,
  100.                       unsigned vtable, unsigned queryinterface, int methodno);
  101.     
  102. //    int  LoadInterface(REFCLSID rclsid, REFIID riid);
  103.  
  104.     void FreeModules(void);
  105. };
  106.