home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_02 / SysCall / SysCall.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-17  |  4.7 KB  |  182 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   : syscall.cpp                                                         //
  10. //  Description: Listing system service calls, and call routines, Chapter 2          //
  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 <assert.h>
  19. #include <tchar.h>
  20. #include <imagehlp.h> 
  21. #include <richedit.h>
  22. #include <stdio.h>
  23. #include <commctrl.h>
  24.  
  25. #include "resource.h"
  26. #include "..\..\include\win.h"
  27. #include "..\..\include\ImageModule.h"
  28.  
  29.  
  30. class KMainWindow : public KWindow
  31. {
  32.     virtual LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  33.  
  34.     HINSTANCE m_hInst;
  35.  
  36.     void GetWndClassEx(WNDCLASSEX & wc)
  37.     {
  38.         KWindow::GetWndClassEx(wc);
  39.         wc.hIcon  = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_GRAPH));
  40.     }
  41.  
  42. public:
  43.  
  44.     HWND      m_Output;
  45.  
  46.     KMainWindow(HINSTANCE hInst)
  47.     {
  48.         m_hInst   = hInst;
  49.         m_Output  = NULL;
  50.     }
  51.  
  52.     void ListSysCalls(char * module, char * extension, bool bForPogy=false);
  53.     void SysCallTable(char * module, char * extension, const char * tablename, unsigned base);
  54. };
  55.  
  56.  
  57. void KMainWindow::ListSysCalls(char * module, char * extension, bool bForPogy)
  58. {
  59.     KImageModule mod(m_Output);
  60.  
  61.     mod.LoadSystemModule(module, extension);
  62.     mod.EnumerateSymbols(bForPogy);
  63. }
  64.  
  65.  
  66. void KMainWindow::SysCallTable(char * module, char * extension, const char * tablename, unsigned base)
  67. {
  68.     KImageModule mod(m_Output);
  69.  
  70.     mod.LoadSystemModule(module, extension);
  71.     mod.ShowSysCallTable(tablename, base);
  72. }
  73.  
  74.  
  75. LRESULT KMainWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  76. {
  77.     switch( uMsg )
  78.     {
  79.         case WM_CREATE:
  80.             {
  81.                 RECT rect;
  82.  
  83.                 m_hWnd  = hWnd;
  84.             
  85.                 GetClientRect(m_hWnd, & rect);
  86.  
  87.                 m_Output = CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASS, NULL, 
  88.                     WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL |
  89.                     ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOVSCROLL | ES_WANTRETURN,
  90.                     0, 0, rect.right, rect.bottom,
  91.                     m_hWnd, NULL, m_hInst, NULL);
  92.  
  93.                 assert(m_Output);
  94.                 SendMessage(m_Output, WM_SETFONT, (WPARAM) GetStockObject(ANSI_FIXED_FONT), FALSE);;
  95.             }
  96.             return 0;
  97.  
  98.         case WM_SIZE:
  99.             {
  100.                 int width       = LOWORD(lParam);
  101.                 int height       = HIWORD(lParam);
  102.  
  103.                 MoveWindow(m_Output, 0, 0, width, height, TRUE);
  104.             }
  105.             return 0;
  106.  
  107.         case WM_PAINT:
  108.             {
  109.                 PAINTSTRUCT ps; 
  110.                 
  111.                 BeginPaint(m_hWnd, &ps);
  112.                 EndPaint(m_hWnd, &ps);
  113.             }
  114.             return 0;
  115.  
  116.         case WM_COMMAND:
  117.  
  118.             switch ( LOWORD(wParam) )
  119.             {
  120.                 case ID_EXIT:
  121.                     DestroyWindow(hWnd);
  122.                     return 0;
  123.  
  124.                 case ID_GDI_POGY:
  125.                     ListSysCalls(_T("gdi32.dll"), _T("dll"), true);
  126.                     return 0;
  127.  
  128.                 case ID_GDI_SYSCALL:
  129.                     ListSysCalls(_T("gdi32.dll"), _T("dll"));
  130.                     return 0;
  131.  
  132.                 case ID_USER_SYSCALL:
  133.                     ListSysCalls(_T("user32.dll"), _T("dll"));
  134.                     return 0;
  135.  
  136.                 case ID_NTDLL_SYSCALL:
  137.                     ListSysCalls(_T("ntdll.dll"), _T("dll"));
  138.                     return 0;
  139.  
  140.                 case ID_WIN32K_SYSCALLTAB:
  141.                     SysCallTable(_T("win32k.sys"), _T("sys"), _T("W32pServiceTable"), 0x1000);
  142.                     return 0;
  143.  
  144.                 case ID_NTOSKRNL_SYSCALLTAB:
  145.                     SysCallTable(_T("ntoskrnl.exe"), _T("exe"), _T("KiServiceTable"), 0);
  146.                     return 0;
  147.  
  148.             }
  149.             break;
  150.  
  151.         case WM_DESTROY:
  152.             PostQuitMessage(0);
  153.             return 0;
  154.     }
  155.  
  156.     return DefWindowProc(hWnd, uMsg, wParam, lParam);
  157. }
  158.  
  159.  
  160. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmd, int nShow)
  161. {
  162.     if ( LoadLibrary(_T("RICHED20.DLL"))==NULL )
  163.     {
  164.         MessageBox(NULL, _T("Unable to load RICHED20.DLL"), _T("SysCall"), MB_OK);
  165.         return -1;
  166.     }
  167.     
  168.     KMainWindow win(hInst);
  169.     
  170.     win.CreateEx(0, _T("SysCall"), _T("SysCall"),
  171.                  WS_OVERLAPPEDWINDOW,
  172.                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
  173.                  NULL, LoadMenu(hInst, MAKEINTRESOURCE(IDR_MAIN)), hInst);
  174.         
  175.     win.ShowWindow(nShow);
  176.     win.UpdateWindow();
  177.     win.MessageLoop();
  178.  
  179.     return 0;
  180. }
  181.  
  182.