Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.6 KiB

  1. /*
  2. * Dynamically link to DCI entry points.
  3. * To implement dynamic linking
  4. * 1. include this file in DRAWDIB.C
  5. * 2. include a call in DRAWDIB.C to InitialiseDCI()
  6. * 3. include a call in DRAWDIB.C to TerminateDCI()
  7. * at the appropriate points.
  8. * There are no other changes.
  9. * To revert to static linking you can simply modify this file or
  10. * #define STATIC_LINK_TO_DCI during the compilation phase.
  11. * AND link to DCIMAN32.LIB
  12. *
  13. * IF the code adds calls to other DCI entry points they will have to be
  14. * added to this file. You should find that out easily enough as there will
  15. * be an unresolved reference on linking (assuming that DCIMAN32.LIB is not
  16. * included in the libraries list).
  17. *
  18. * The process is straightforward.
  19. * string variables are defined to hold the
  20. * names of the DCI function entry points.
  21. * function variables are defined for each entry point being indirected
  22. * the code is added to GetProcAddress for each entry
  23. * a #define is added to point the DCI entry point name at the function variable
  24. */
  25. #ifdef STATIC_LINK_TO_DCI
  26. #define InitialiseDCI() 1
  27. #define TerminateDCI()
  28. #else
  29. static const char DCILIBRARY[] = "DCIMAN32.DLL";
  30. static HINSTANCE hlibDCI;
  31. static BOOL fDCILinked;
  32. static UINT cDCIUsers; // Count of active DCI users
  33. char szDCIOpenProvider[] = "DCIOpenProvider";
  34. char szDCICloseProvider[] = "DCICloseProvider";
  35. char szDCICreatePrimary[] = "DCICreatePrimary";
  36. char szDCIEndAccess[] = "DCIEndAccess";
  37. char szDCIBeginAccess[] = "DCIBeginAccess";
  38. char szDCIDestroy[] = "DCIDestroy";
  39. HDC (WINAPI *pfnDCIOpenProvider)(void);
  40. void (WINAPI *pfnDCICloseProvider)(HDC hdc);
  41. int (WINAPI *pfnDCICreatePrimary)(HDC hdc, LPDCISURFACEINFO FAR *lplpSurface);
  42. void (WINAPI *pfnDCIEndAccess)(LPDCISURFACEINFO pdci);
  43. DCIRVAL (WINAPI *pfnDCIBeginAccess)(LPDCISURFACEINFO pdci, int x, int y, int dx, int dy);
  44. void (WINAPI *pfnDCIDestroy)(LPDCISURFACEINFO pdci);
  45. BOOL InitialiseDCI(void);
  46. __inline BOOL InitialiseDCI()
  47. {
  48. ++cDCIUsers;
  49. if (fDCILinked) {
  50. // Already linked
  51. return(TRUE);
  52. }
  53. hlibDCI = LoadLibraryA(DCILIBRARY);
  54. if (hlibDCI) {
  55. (FARPROC)pfnDCIOpenProvider = GetProcAddress(hlibDCI, szDCIOpenProvider);
  56. (FARPROC)pfnDCICloseProvider = GetProcAddress(hlibDCI, szDCICloseProvider);
  57. (FARPROC)pfnDCICreatePrimary = GetProcAddress(hlibDCI, szDCICreatePrimary);
  58. (FARPROC)pfnDCIEndAccess = GetProcAddress(hlibDCI, szDCIEndAccess);
  59. (FARPROC)pfnDCIBeginAccess = GetProcAddress(hlibDCI, szDCIBeginAccess);
  60. (FARPROC)pfnDCIDestroy = GetProcAddress(hlibDCI, szDCIDestroy);
  61. if (pfnDCIOpenProvider &&
  62. pfnDCICloseProvider &&
  63. pfnDCICreatePrimary &&
  64. pfnDCIEndAccess &&
  65. pfnDCIBeginAccess &&
  66. pfnDCIDestroy) {
  67. fDCILinked = TRUE;
  68. } else {
  69. --cDCIUsers;
  70. FreeLibrary(hlibDCI);
  71. hlibDCI = NULL;
  72. }
  73. }
  74. return fDCILinked;
  75. }
  76. #define TerminateDCI() \
  77. if (hlibDCI && !--cDCIUsers) {\
  78. FreeLibrary(hlibDCI); \
  79. fDCILinked = FALSE; \
  80. hlibDCI = NULL; \
  81. }
  82. // Map the static names to the function pointers.
  83. #define DCIOpenProvider pfnDCIOpenProvider
  84. #define DCICloseProvider pfnDCICloseProvider
  85. #define DCICreatePrimary pfnDCICreatePrimary
  86. #define DCIEndAccess pfnDCIEndAccess
  87. #define DCIBeginAccess pfnDCIBeginAccess
  88. #define DCIDestroy pfnDCIDestroy
  89. #endif