Source code of Windows XP (NT5)
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.

213 lines
7.5 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // File: clsdesc.cxx
  4. //
  5. // Contents: ClassDescriptor implementation
  6. //
  7. //------------------------------------------------------------------------
  8. //[ classdescriptor_overview
  9. /*
  10. ClassDescriptor Overview
  11. A ClassDescriptor is a structure the contains global, static information
  12. about an OLE Compound Document class. Having a ClassDescriptor allows
  13. the base classes to do a lot of work on behalf of the derived class because
  14. it can get information it needs from the ClassDescriptor instead of resorting
  15. to virtual method calls. A single ClassDescriptor is shared by all object
  16. instances of that Compound Document class.
  17. A ClassDescriptor has three conceptual parts. The first part is a collection
  18. of information loaded from resources. This includes strings, menus, accelerators,
  19. and an icon. The second part is a pair of verb tables that are used to implement
  20. IOleObject::DoVerb. The third part is two pairs of format tables that are
  21. used to implement many of the Get/Set/Query methods on IDataObject.
  22. Each of these parts has its own initialization method to prepare that part of
  23. the class descriptor.
  24. The ClassDescriptor is usually associated with the ClassFactory.
  25. */
  26. //]
  27. #include "headers.hxx"
  28. #pragma hdrstop
  29. #define MAX_USERTYPE_LEN 64
  30. //+---------------------------------------------------------------
  31. //
  32. // Member: ClassDescriptor::ClassDescriptor
  33. //
  34. // Synopsis: Constructor for ClassDescriptor structure
  35. //
  36. // Notes: A DLL (in-process) server should allocate the class
  37. // descriptor at library initialization time and allocate
  38. // it in shared memory (GMEM_SHARE flag with GlobalAlloc, or
  39. // the OLE shared allocator, MEMCTX_SHARED).
  40. //
  41. // The constructor ensures all members of the structure
  42. // are initialized to NULL
  43. //
  44. //----------------------------------------------------------------
  45. ClassDescriptor::ClassDescriptor(void)
  46. {
  47. // initialize everything to NULL
  48. // ZeroMemory(this, sizeof(ClassDescriptor));
  49. memset(this, 0, sizeof(ClassDescriptor));
  50. }
  51. //+---------------------------------------------------------------
  52. //
  53. // Member: ClassDescriptor::Init
  54. //
  55. // Synopsis: Initializes a class descriptor structure from resources
  56. //
  57. // Arguments: [hinst] -- instance handle of module with resources used
  58. // to initialize the class descriptor
  59. //
  60. // Returns: TRUE iff the class descriptor was successfully initialized
  61. //
  62. // Notes: This method only fills in the part of the class descriptor
  63. // that can be initialized from resources. The other part
  64. // that requires initialization are the verb and format tables.
  65. //
  66. // Objects that are concerned about resource load times could
  67. // not use this initialization method and fill in fields of the
  68. // class descriptor directly.
  69. //
  70. //----------------------------------------------------------------
  71. BOOL ClassDescriptor::Init(HINSTANCE hinst, WORD wBaseID)
  72. {
  73. //REVIEW: Currently, information loaded from resources is duplicated
  74. //REVIEW: in the registration database. We could
  75. //REVIEW: (1) load this stuff from the reg db instead (except CLSID), or
  76. //REVIEW: (2) do an autoregistration feature where the reg db is filled
  77. //REVIEW: in from the class descriptor information loaded from resources
  78. //REVIEW: We could also support loading the verb and format tables
  79. //REVIEW: from resources/regdb as well.
  80. _hinst = hinst;
  81. _wBaseResID = wBaseID;
  82. // load our class id string and convert it into our real class id
  83. TCHAR szClsId[40];
  84. ZeroMemory (szClsId, sizeof (szClsId));
  85. LoadString(hinst, wBaseID+IDOFF_CLASSID, szClsId, ARRAY_SIZE(szClsId));
  86. #if !defined(UNICODE) && !defined(OLE2ANSI)
  87. LPOLESTR lpostr = ConvertMBToOLESTR(szClsId,-1);
  88. BOOL fRet = OK(CLSIDFromString(lpostr, &_clsid));
  89. TaskFreeMem(lpostr);
  90. #else
  91. BOOL fRet = OK(CLSIDFromString(szClsId, &_clsid));
  92. #endif
  93. // load our in-place menus and accelerators
  94. _hicon = LoadIcon(hinst, MAKEINTRESOURCE(wBaseID+IDOFF_ICON));
  95. _haccel = (HACCEL)LoadAccelerators(hinst,
  96. MAKEINTRESOURCE(wBaseID+IDOFF_ACCELS));
  97. LoadResourceData(hinst,
  98. MAKEINTRESOURCE(wBaseID+IDOFF_MGW),
  99. &_mgw,
  100. sizeof(_mgw));
  101. LoadResourceData(hinst,
  102. MAKEINTRESOURCE(wBaseID+IDOFF_MISCSTATUS),
  103. &_dwMiscStatus,
  104. sizeof(_dwMiscStatus));
  105. #if !defined(UNICODE) && !defined(OLE2ANSI)
  106. CHAR szUserClassType[MAX_USERTYPE_LEN];
  107. #define SetWideClassType(y,x) \
  108. MultiByteToWideChar(CP_ACP \
  109. , 0 \
  110. , (y) \
  111. , -1 \
  112. , _szUserClassType[(x)] \
  113. , ARRAY_SIZE(_szUserClassType[(x)]))
  114. LoadString(hinst
  115. , wBaseID+IDOFF_USERTYPEFULL
  116. , szUserClassType
  117. , MAX_USERTYPE_LEN);
  118. SetWideClassType(szUserClassType,USERCLASSTYPE_FULL);
  119. LoadString(hinst
  120. , wBaseID+IDOFF_USERTYPESHORT
  121. , szUserClassType
  122. , MAX_USERTYPE_LEN);
  123. SetWideClassType(szUserClassType,USERCLASSTYPE_SHORT);
  124. LoadString(hinst
  125. , wBaseID+IDOFF_USERTYPEAPP
  126. , szUserClassType
  127. , MAX_USERTYPE_LEN);
  128. SetWideClassType(szUserClassType,USERCLASSTYPE_APPNAME);
  129. LoadString(hinst
  130. , wBaseID+IDOFF_DOCFEXT
  131. , szUserClassType
  132. , MAX_USERTYPE_LEN);
  133. MultiByteToWideChar(CP_ACP
  134. , 0
  135. , szUserClassType
  136. , -1
  137. , _szDocfileExt
  138. , ARRAY_SIZE(_szDocfileExt));
  139. #else
  140. LoadString(hinst
  141. , wBaseID+IDOFF_USERTYPEFULL
  142. , _szUserClassType[USERCLASSTYPE_FULL]
  143. , ARRAY_SIZE(_szUserClassType[USERCLASSTYPE_FULL]));
  144. LoadString(hinst
  145. , wBaseID+IDOFF_USERTYPESHORT
  146. , _szUserClassType[USERCLASSTYPE_SHORT]
  147. , ARRAY_SIZE(_szUserClassType[USERCLASSTYPE_SHORT]));
  148. LoadString(hinst
  149. , wBaseID+IDOFF_USERTYPEAPP
  150. , _szUserClassType[USERCLASSTYPE_APPNAME]
  151. , ARRAY_SIZE(_szUserClassType[USERCLASSTYPE_APPNAME]));
  152. LoadString(hinst
  153. , wBaseID+IDOFF_DOCFEXT
  154. , _szDocfileExt
  155. , ARRAY_SIZE(_szDocfileExt));
  156. #endif
  157. return fRet;
  158. }
  159. //+---------------------------------------------------------------
  160. //
  161. // Member: ClassDescriptor::LoadMenu, public
  162. //
  163. // Synopsis: Loads a copy of the menus for the server
  164. //
  165. // Notes: A single copy of the menu cannot be shared by all
  166. // instances of the class, like an accelerator table can.
  167. // This is because the menu is not a read-only resource
  168. // (e.g. you can "check" a menu item and merge in verb
  169. // menu items). Therefore each class instance must load
  170. // its own copy of the menu. This LoadMenu call is used
  171. // for that purpose.
  172. //
  173. //---------------------------------------------------------------
  174. HMENU
  175. ClassDescriptor::LoadMenu(void)
  176. {
  177. return ::LoadMenu(_hinst, MAKEINTRESOURCE(_wBaseResID+IDOFF_MENU));
  178. }
  179.