home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / common / wrap3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  4.3 KB  |  202 lines

  1. /*
  2.  *  WRAP3D.C
  3.  */
  4.  
  5. #include <windows.h>
  6. #include <mapix.h>
  7. #ifdef  WIN16
  8. #include <memory.h>
  9. #endif  
  10. #include <mapiwin.h>
  11. #include "wrap3d.h"
  12.  
  13. STDAPI_(LPVOID)
  14. CTL3D_Initialize(HINSTANCE hinstMe)
  15. {
  16.     UINT        fuErr;
  17.     HINSTANCE   hinst = 0;
  18.     BOOL        fRegistered = FALSE;    /* assume failure */
  19.     FARPROC     fpEnabled;
  20.     FARPROC     fpRegister;
  21.     LPCTX3D     pctx = NULL;
  22.     DWORD       dwVer;
  23.  
  24.     /*
  25.      * //$ If the Win 4 shell is present, don't even look for the DLL.
  26.      * //$ Need to verify this algorithm.
  27.      */
  28.  
  29.     dwVer = GetVersion();
  30.     if (LOBYTE(LOWORD(dwVer)) >= 4)
  31.         goto fail;
  32.  
  33. #ifdef _WIN32
  34.     pctx = LocalAlloc(LPTR, sizeof(CTX3D));
  35.     if (!pctx)
  36.         goto fail;
  37. #else
  38.     if (MAPIAllocateBuffer(sizeof(CTX3D), &pctx))
  39.         goto fail;
  40. #endif
  41.     ZeroMemory(pctx, sizeof(CTX3D));
  42.  
  43.     /* Attempt to load the DLL. Do not allow any error messages. */
  44.     fuErr = SetErrorMode(SEM_NOOPENFILEERRORBOX);
  45. #ifdef  _WIN32
  46.     hinst = LoadLibraryA("CTL3D32.DLL");
  47.     SetErrorMode(fuErr);
  48.     if (!hinst)
  49.         goto fail;
  50. #else
  51.     hinst = LoadLibrary("CTL3DV2.DLL");
  52.     SetErrorMode(fuErr);
  53.     if (hinst < HINSTANCE_ERROR)
  54.         goto fail;
  55. #endif
  56.  
  57.     /* Get the entry points we need. */
  58.     if (!(fpEnabled = GetProcAddress(hinst, "Ctl3dEnabled")))
  59.         goto fail;
  60.     if (!(fpRegister = GetProcAddress(hinst, "Ctl3dRegister")))
  61.         goto fail;
  62.     if (!(pctx->fpUnregister = GetProcAddress(hinst, "Ctl3dUnregister")))
  63.         goto fail;
  64.     if (!(pctx->fpSubclassDlgEx = GetProcAddress(hinst, "Ctl3dSubclassDlgEx")))
  65.         goto fail;
  66.     if (!(pctx->fpColorChange = GetProcAddress(hinst, "Ctl3dColorChange")))
  67.         goto fail;
  68.     if ((pctx->fpIsAutoSubclass = GetProcAddress(hinst, "Ctl3dIsAutoSubclass")) &&
  69.         (!(pctx->fpAutoSubclass = GetProcAddress(hinst, "Ctl3dAutoSubclass")) ||
  70.         !(pctx->fpUnAutoSubclass = GetProcAddress(hinst, "Ctl3dUnAutoSubclass"))))
  71.         goto fail;
  72.     if (!(pctx->fpSubclassCtl = GetProcAddress(hinst, "Ctl3dSubclassCtl")))
  73.         goto fail;
  74.     if (!(pctx->fpGetVer = GetProcAddress(hinst, "Ctl3dGetVer")))
  75.         goto fail;
  76.  
  77.     /* If we were not already registered, do so. */
  78.     if (!(*fpEnabled)())
  79.         pctx->fRegistered = (*fpRegister)(hinstMe);
  80.  
  81.     /* Remember the library handle. */
  82.     pctx->hinst = hinst;
  83.     pctx->hinstMe = hinstMe;
  84.  
  85. ret:
  86.     return pctx;
  87.  
  88. fail:
  89.     if (hinst)
  90.         FreeLibrary(hinst);
  91. #ifdef  _WIN32
  92.     if (pctx)
  93.         LocalFree(pctx);
  94. #else
  95.     MAPIFreeBuffer(pctx);
  96. #endif  
  97.     pctx = NULL;
  98.     goto ret;
  99. }
  100.  
  101. STDAPI_(void)
  102. CTL3D_Uninitialize(LPVOID lpv)
  103. {
  104.     LPCTX3D pctx;
  105.  
  106.     if (!(pctx = (LPCTX3D) lpv))
  107.         return;
  108.  
  109.     if (pctx->fRegistered)
  110.         (*(pctx->fpUnregister))(pctx->hinstMe);
  111.  
  112.     FreeLibrary(pctx->hinst);
  113.  
  114. #ifdef  _WIN32
  115.     LocalFree(pctx);
  116. #else
  117.     MAPIFreeBuffer(pctx);
  118. #endif  
  119. }
  120.  
  121. STDAPI_(void)
  122. CTL3D_Subclass(LPVOID lpv, HWND hwnd, DWORD dwFlags)
  123. {
  124.     LPCTX3D pctx;
  125.  
  126.     if (!(pctx = (LPCTX3D) lpv))
  127.         return;
  128.  
  129.     (*(pctx->fpSubclassDlgEx))(hwnd, dwFlags);
  130. }
  131.  
  132. STDAPI_(void)
  133. CTL3D_AutoSubclass(LPVOID lpv, HINSTANCE hinst, BOOL FAR * lpfAuto)
  134. {
  135.     LPCTX3D pctx;
  136.  
  137.     *lpfAuto = FALSE;
  138.     if (!(pctx = (LPCTX3D) lpv) || !pctx->fpIsAutoSubclass)
  139.         return;
  140.  
  141.     if (*lpfAuto = !pctx->fpIsAutoSubclass())
  142.         pctx->fpAutoSubclass (hinst);
  143.  
  144.     return;
  145. }
  146.  
  147. STDAPI_(BOOL)
  148. CTL3D_IsAutoSubclass(LPVOID lpv)
  149. {
  150.     LPCTX3D pctx;
  151.  
  152.     if (!(pctx = (LPCTX3D) lpv) || !pctx->fpIsAutoSubclass)
  153.         return FALSE;
  154.  
  155.     return pctx->fpIsAutoSubclass();
  156. }
  157.  
  158. STDAPI_(void)
  159. CTL3D_CeaseAutoSubclass(LPVOID lpv, BOOL fAuto)
  160. {
  161.     LPCTX3D pctx;
  162.  
  163.     if (!(pctx = (LPCTX3D) lpv) || !fAuto)
  164.         return;
  165.  
  166.     pctx->fpUnAutoSubclass ();
  167.     return;
  168. }
  169.  
  170. STDAPI_(BOOL)
  171. CTL3D_ColorChange(LPVOID lpv)
  172. {
  173.     LPCTX3D pctx;
  174.  
  175.     if (!(pctx = (LPCTX3D) lpv))
  176.         return FALSE;
  177.  
  178.     return pctx->fpColorChange();
  179. }
  180.  
  181. STDAPI_(BOOL)
  182. CTL3D_SubclassCtl(LPVOID lpv, HWND hwnd)
  183. {
  184.     LPCTX3D pctx;
  185.  
  186.     if (!(pctx = (LPCTX3D) lpv))
  187.         return FALSE;
  188.  
  189.     return pctx->fpSubclassCtl(hwnd);
  190. }
  191.  
  192. STDAPI_(WORD)
  193. CTL3D_GetVer(LPVOID lpv)
  194. {
  195.     LPCTX3D pctx;
  196.  
  197.     if (!(pctx = (LPCTX3D) lpv))
  198.         return 0;
  199.  
  200.     return pctx->fpGetVer();
  201. }
  202.