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.

82 lines
2.2 KiB

  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * Helper for GDI+ initialization
  8. *
  9. * Abstract:
  10. *
  11. * This code initializes GDI+ (with default parameters).
  12. * The code is specific to our compiler, because it uses #pragma to
  13. * get our code to be initialized before the app's other global objects
  14. * (important when apps make global GDI+ objects.)
  15. *
  16. * Notes:
  17. *
  18. * A test app should include this in *just one* of its .cpp files.
  19. * It should check gGdiplusInitHelper.IsValid() in its main function,
  20. * and abort if it returns FALSE.
  21. *
  22. * We use "#pragma code_seg()", which resets the code segment to "whatever
  23. * it was when compilation began" (MSDN). In other words, we stomp on whatever
  24. * the code segment might have been changed to before this file was included.
  25. * You don't need to worry about this unless you use "#pragma code_seg"
  26. * yourself, in the file which includes this one.
  27. *
  28. * Created:
  29. *
  30. * 09/18/2000 agodfrey
  31. * Created it.
  32. *
  33. **************************************************************************/
  34. #include <objbase.h>
  35. #include "gdiplus.h"
  36. // Disable the stupid warning that says we have a "lib" code segment.
  37. #pragma warning( push )
  38. #pragma warning( disable : 4073 )
  39. // Make a separate code segment, and mark it as a "library initialization"
  40. // segment
  41. #pragma code_seg( "GpInit" )
  42. #pragma init_seg( lib )
  43. class GdiplusInitHelper
  44. {
  45. public:
  46. GdiplusInitHelper() : gpToken(0), Valid(FALSE)
  47. {
  48. Gdiplus::GdiplusStartupInput sti;
  49. if (Gdiplus::GdiplusStartup(&gpToken, &sti, NULL) == Gdiplus::Ok)
  50. {
  51. Valid = TRUE;
  52. }
  53. }
  54. ~GdiplusInitHelper()
  55. {
  56. if (Valid)
  57. {
  58. Gdiplus::GdiplusShutdown(gpToken);
  59. }
  60. }
  61. BOOL IsValid() { return Valid; }
  62. private:
  63. ULONG_PTR gpToken;
  64. BOOL Valid;
  65. };
  66. // Declare the global in this code segment, so that it is initialized before/
  67. // destroyed after the app's globals.
  68. GdiplusInitHelper gGdiplusInitHelper;
  69. // Reset the code segment to "whatever it was when compilation began".
  70. #pragma code_seg()
  71. #pragma warning( pop )