pifmgr.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //
  2. //  Thunks for calling PIFMGR.DLL from Shell32.dll
  3. //
  4. // PifMgr_OpenProperties
  5. // PifMgr_CloseProperties
  6. // PifMgr_GetProperties
  7. // PifMgr_SetProperties
  8. //
  9. //  PIFMGR.DLL will be kept loaded as long as a PIF PROPERTIES handle is open
  10. //  and will be free'ed (via FreeLibrary) when the last handle is closed.
  11. //
  12. #include "shprv.h"
  13. #include <pif.h>
  14. static HMODULE hPifMgrDll;
  15. static UINT    cRef;
  16. static int  (WINAPI *XOpenProperties)(LPCSTR lpszApp, LPCSTR lpszPIF, int hInf, int flOpt);
  17. static int  (WINAPI *XGetProperties)(int hProps, LPCSTR lpszGroup, LPVOID lpProps, int cbProps, int flOpt);
  18. static int  (WINAPI *XSetProperties)(int hProps, LPCSTR lpszGroup, const VOID FAR *lpProps, int cbProps, int flOpt);
  19. static int  (WINAPI *XCloseProperties)(int hProps, int flOpt);
  20. static char szPifMgrDll[] = "PIFMGR.DLL";
  21. /*****************************************************************************
  22.  ****************************************************************************/
  23. BOOL PifMgr_Load()
  24. {
  25.     if (hPifMgrDll == NULL)
  26.     {
  27.         DebugMsg(DM_TRACE, "pif: Loading PIFMGR.DLL");
  28.         hPifMgrDll = LoadLibrary(szPifMgrDll);
  29.         if (hPifMgrDll <= HINSTANCE_ERROR)
  30.         {
  31.             hPifMgrDll = NULL;
  32.             return FALSE;
  33.         }
  34.         (FARPROC)XOpenProperties  = GetProcAddress(hPifMgrDll, MAKEINTATOM(ORD_OPENPROPERTIES));
  35.         (FARPROC)XCloseProperties = GetProcAddress(hPifMgrDll, MAKEINTATOM(ORD_CLOSEPROPERTIES));
  36.         (FARPROC)XGetProperties   = GetProcAddress(hPifMgrDll, MAKEINTATOM(ORD_GETPROPERTIES));
  37.         (FARPROC)XSetProperties   = GetProcAddress(hPifMgrDll, MAKEINTATOM(ORD_SETPROPERTIES));
  38.     }
  39.     return TRUE;
  40. }
  41. /*****************************************************************************
  42.  ****************************************************************************/
  43. void PifMgr_Free()
  44. {
  45.     HMODULE h;
  46.     if (cRef == 0 && (h=hPifMgrDll))
  47.     {
  48.         DebugMsg(DM_TRACE, "pif: Unloading PIFMGR.DLL");
  49.         hPifMgrDll = NULL;
  50.         FreeLibrary(h);
  51.         XOpenProperties  = NULL;
  52.         XCloseProperties = NULL;
  53.         XGetProperties   = NULL;
  54.         XSetProperties   = NULL;
  55.     }
  56. }
  57. /*****************************************************************************
  58.  ****************************************************************************/
  59. int WINAPI PifMgr_OpenProperties(LPCSTR lpszApp, LPCSTR lpszPIF, int hInf, int flOpt)
  60. {
  61.     int hpif=NULL;
  62.     if (PifMgr_Load())
  63.     {
  64.         cRef++;
  65.         hpif = XOpenProperties(lpszApp, lpszPIF, hInf, flOpt);
  66.         if (hpif == NULL)
  67.             cRef--;
  68.     }
  69.     return hpif;
  70. }
  71. /*****************************************************************************
  72.  ****************************************************************************/
  73. int WINAPI PifMgr_GetProperties(int hProps, LPCSTR lpszGroup, LPVOID lpProps, int cbProps, int flOpt)
  74. {
  75.     if (PifMgr_Load())
  76.         return XGetProperties(hProps, lpszGroup, lpProps, cbProps,  flOpt);
  77.     else
  78.         return 0;
  79. }
  80. /*****************************************************************************
  81.  ****************************************************************************/
  82. int WINAPI PifMgr_SetProperties(int hProps, LPCSTR lpszGroup, const VOID FAR *lpProps, int cbProps, int flOpt)
  83. {
  84.     if (PifMgr_Load())
  85.         return XSetProperties(hProps, lpszGroup, lpProps, cbProps,  flOpt);
  86.     else
  87.         return 0;
  88. }
  89. /*****************************************************************************
  90.  ****************************************************************************/
  91. int WINAPI PifMgr_CloseProperties(int hProps, int flOpt)
  92. {
  93.     int i;
  94.     //
  95.     // SHELL32.DLL calls this (with NULL) on thread detach to
  96.     // give us a chance to free PIFMGR if we dont need it.
  97.     //
  98.     if (hProps == NULL)
  99.     {
  100.         PifMgr_Free();
  101.     }
  102.     else if (cRef > 0)
  103.     {
  104.         i = XCloseProperties(hProps, flOpt);
  105.         cRef--;
  106.     }
  107.     return i;
  108. }