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.

312 lines
8.8 KiB

  1. // AppParse.h : Declaration of the CAppParse
  2. #ifndef __APPPARSE_H_
  3. #define __APPPARSE_H_
  4. #include "resource.h" // main symbols
  5. #include <atlctl.h>
  6. #include <windows.h>
  7. #include <icrsint.h>
  8. #include <oledb.h>
  9. #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
  10. no_namespace rename("EOF", "EndOfFile")
  11. void APError(char* szMessage, HRESULT hr);
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAppParse
  14. class ATL_NO_VTABLE CAppParse :
  15. public CComObjectRootEx<CComSingleThreadModel>,
  16. public IDispatchImpl<IAppParse, &IID_IAppParse, &LIBID_APPPARSEWEBLib>,
  17. public CComControl<CAppParse>,
  18. public IPersistStreamInitImpl<CAppParse>,
  19. public IOleControlImpl<CAppParse>,
  20. public IOleObjectImpl<CAppParse>,
  21. public IOleInPlaceActiveObjectImpl<CAppParse>,
  22. public IViewObjectExImpl<CAppParse>,
  23. public IOleInPlaceObjectWindowlessImpl<CAppParse>,
  24. public IPersistStorageImpl<CAppParse>,
  25. public ISpecifyPropertyPagesImpl<CAppParse>,
  26. public IQuickActivateImpl<CAppParse>,
  27. public IDataObjectImpl<CAppParse>,
  28. public IProvideClassInfo2Impl<&CLSID_AppParse, NULL, &LIBID_APPPARSEWEBLib>,
  29. public CComCoClass<CAppParse, &CLSID_AppParse>,
  30. public IObjectSafetyImpl<CAppParse, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
  31. public IObjectSafetyImpl<CAppParse, INTERFACESAFE_FOR_UNTRUSTED_DATA>
  32. {
  33. private:
  34. char* m_szConnect;
  35. char* m_szPath;
  36. long m_ID;
  37. HANDLE m_hEvent;
  38. public:
  39. CAppParse()
  40. {
  41. m_hEvent = 0;
  42. m_szConnect = 0;
  43. m_szPath = 0;
  44. m_ID = -1;
  45. m_hEvent = CreateEvent(0, TRUE, FALSE, 0);
  46. if(!m_hEvent)
  47. APError("Unable to create kernel object", E_FAIL);
  48. }
  49. ~CAppParse()
  50. {
  51. if(m_hEvent)
  52. CloseHandle(m_hEvent);
  53. if(m_szPath)
  54. delete m_szPath;
  55. }
  56. DECLARE_REGISTRY_RESOURCEID(IDR_APPPARSE)
  57. DECLARE_PROTECT_FINAL_CONSTRUCT()
  58. BEGIN_COM_MAP(CAppParse)
  59. COM_INTERFACE_ENTRY(IAppParse)
  60. COM_INTERFACE_ENTRY(IDispatch)
  61. COM_INTERFACE_ENTRY(IViewObjectEx)
  62. COM_INTERFACE_ENTRY(IViewObject2)
  63. COM_INTERFACE_ENTRY(IViewObject)
  64. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  65. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  66. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  67. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  68. COM_INTERFACE_ENTRY(IOleControl)
  69. COM_INTERFACE_ENTRY(IOleObject)
  70. COM_INTERFACE_ENTRY(IPersistStreamInit)
  71. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  72. COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
  73. COM_INTERFACE_ENTRY(IQuickActivate)
  74. COM_INTERFACE_ENTRY(IPersistStorage)
  75. COM_INTERFACE_ENTRY(IDataObject)
  76. COM_INTERFACE_ENTRY(IProvideClassInfo)
  77. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  78. END_COM_MAP()
  79. BEGIN_PROP_MAP(CAppParse)
  80. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  81. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  82. // Example entries
  83. // PROP_ENTRY("Property Description", dispid, clsid)
  84. // PROP_PAGE(CLSID_StockColorPage)
  85. END_PROP_MAP()
  86. BEGIN_MSG_MAP(CAppParse)
  87. CHAIN_MSG_MAP(CComControl<CAppParse>)
  88. DEFAULT_REFLECTION_HANDLER()
  89. END_MSG_MAP()
  90. // Handler prototypes:
  91. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  92. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  93. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  94. // IViewObjectEx
  95. DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
  96. // IAppParse
  97. public:
  98. STDMETHOD(QueryDB)(long PtolemyID, BSTR bstrFunction);
  99. STDMETHOD(get_ConnectionString)(/*[out, retval]*/ BSTR *pVal);
  100. STDMETHOD(put_ConnectionString)(/*[in]*/ BSTR newVal);
  101. STDMETHOD(get_PtolemyID)(/*[out, retval]*/ long *pVal);
  102. STDMETHOD(put_PtolemyID)(/*[in]*/ long newVal);
  103. STDMETHOD(get_path)(/*[out, retval]*/ BSTR *pVal);
  104. STDMETHOD(put_path)(/*[in]*/ BSTR newVal);
  105. STDMETHOD(Browse)();
  106. STDMETHOD(Parse)();
  107. HRESULT OnDraw(ATL_DRAWINFO& di)
  108. {
  109. RECT& rc = *(RECT*)di.prcBounds;
  110. Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
  111. SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
  112. LPCTSTR pszText = _T("ATL 3.0 : AppParse");
  113. TextOut(di.hdcDraw,
  114. (rc.left + rc.right) / 2,
  115. (rc.top + rc.bottom) / 2,
  116. pszText,
  117. lstrlen(pszText));
  118. return S_OK;
  119. }
  120. };
  121. // All information associated with an EXE or DLL.
  122. struct SImageFileInfo
  123. {
  124. int DateStatus;
  125. double Date;
  126. int SizeStatus;
  127. int Size;
  128. int BinFileVersionStatus;
  129. CHAR BinFileVersion[50];
  130. int BinProductVersionStatus;
  131. CHAR BinProductVersion[50];
  132. int CheckSumStatus;
  133. ULONG CheckSum;
  134. int CompanyNameStatus;
  135. CHAR CompanyName[255];
  136. int ProductVersionStatus;
  137. CHAR ProductVersion[50];
  138. int ProductNameStatus;
  139. CHAR ProductName[255];
  140. int FileDescStatus;
  141. CHAR FileDesc[255];
  142. };
  143. // Record bindings, eases associating database records with C++ structures.
  144. // A Project record, a single entry in the "Projects" table
  145. struct SProjectRecord : public CADORecordBinding
  146. {
  147. BEGIN_ADO_BINDING(SProjectRecord)
  148. // All fields optional
  149. ADO_NUMERIC_ENTRY2(1, adInteger, PtolemyID, 5, 0, TRUE)
  150. ADO_VARIABLE_LENGTH_ENTRY4(2, adVarChar, Name, 255, TRUE)
  151. END_ADO_BINDING()
  152. // A unique identifier for this project.
  153. ULONG PtolemyID;
  154. // A user-friendly name for the project
  155. CHAR Name[255];
  156. };
  157. // A Module (EXE or DLL) record
  158. struct SModuleRecord : public CADORecordBinding
  159. {
  160. BEGIN_ADO_BINDING(SModuleRecord)
  161. // Query the autonumber DllID, don't change
  162. ADO_NUMERIC_ENTRY2(1, adInteger, ModuleID, 5, 0, FALSE)
  163. // At least one of these fields must be present
  164. ADO_NUMERIC_ENTRY(2, adInteger, ParentID, 5, 0, PtolemyIDStatus, TRUE)
  165. ADO_NUMERIC_ENTRY(3, adInteger, ParentID, 5, 0, ParentIDStatus, TRUE)
  166. // Required fields
  167. ADO_VARIABLE_LENGTH_ENTRY4(4, adVarChar, Name, 255, TRUE)
  168. ADO_FIXED_LENGTH_ENTRY2(5, adBoolean, SysMod, TRUE)
  169. // Optional fields
  170. ADO_FIXED_LENGTH_ENTRY(6, adDate, info.Date, info.DateStatus, TRUE)
  171. ADO_NUMERIC_ENTRY(7, adInteger, info.Size, 5, 0, info.SizeStatus, TRUE)
  172. ADO_VARIABLE_LENGTH_ENTRY2(8, adVarChar, info.BinFileVersion, 50,
  173. info.BinFileVersionStatus, TRUE)
  174. ADO_VARIABLE_LENGTH_ENTRY2(9, adVarChar, info.BinProductVersion, 50,
  175. info.BinProductVersionStatus, TRUE)
  176. ADO_NUMERIC_ENTRY(10, adInteger, info.CheckSum, 5, 0, info.CheckSumStatus, TRUE)
  177. ADO_VARIABLE_LENGTH_ENTRY2(11, adVarChar, info.CompanyName, 255, info.CompanyNameStatus, TRUE)
  178. ADO_VARIABLE_LENGTH_ENTRY2(12, adVarChar, info.ProductVersion, 50, info.ProductVersionStatus, TRUE)
  179. ADO_VARIABLE_LENGTH_ENTRY2(13, adVarChar, info.ProductName, 255, info.ProductNameStatus, TRUE)
  180. ADO_VARIABLE_LENGTH_ENTRY2(14, adVarChar, info.FileDesc, 255, info.FileDescStatus, TRUE)
  181. END_ADO_BINDING()
  182. public:
  183. // Unique ID for this entry (autonumber, done by DB)
  184. ULONG ModuleID;
  185. // Whether this module belongs to a project or
  186. // is a child of another module
  187. int PtolemyIDStatus;
  188. int ParentIDStatus;
  189. // Parent's ID (either Ptolemy or Module)
  190. ULONG ParentID;
  191. // Filename of this module.
  192. CHAR Name[255];
  193. // File info
  194. SImageFileInfo info;
  195. // Whether or not this is a "system" module (like kernel32, user, gdi, advapi, etc.)
  196. DWORD SysMod;
  197. };
  198. // A Function Record
  199. struct SFunctionRecord : public CADORecordBinding
  200. {
  201. BEGIN_ADO_BINDING(SFunctionRecord)
  202. // Required fields
  203. ADO_NUMERIC_ENTRY2(1, adInteger, FunctionID, 5, 0, FALSE)
  204. ADO_NUMERIC_ENTRY2(2, adInteger, ModuleID, 5, 0, TRUE)
  205. ADO_VARIABLE_LENGTH_ENTRY4(3, adVarChar, Name, 255, TRUE)
  206. ADO_FIXED_LENGTH_ENTRY2(8, adBoolean, Delayed, TRUE)
  207. // Optional fields
  208. ADO_NUMERIC_ENTRY(4, adInteger, Address, 5,0,AddressStatus, TRUE)
  209. ADO_NUMERIC_ENTRY(5, adInteger, Ordinal, 5, 0, OrdinalStatus, TRUE)
  210. ADO_NUMERIC_ENTRY(6, adInteger, Hint, 5, 0, HintStatus, TRUE)
  211. ADO_VARIABLE_LENGTH_ENTRY2(7, adVarChar, ForwardName, 255,
  212. ForwardNameStatus, TRUE)
  213. END_ADO_BINDING()
  214. public:
  215. // Unique ID for this function (autonumber, given by the DB)
  216. ULONG FunctionID;
  217. // Parent module
  218. ULONG ModuleID;
  219. // Imported function name
  220. CHAR Name[255];
  221. // Address, if bound
  222. int AddressStatus;
  223. ULONG Address;
  224. // Ordinal, if ordinal import
  225. int OrdinalStatus;
  226. ULONG Ordinal;
  227. // Hint, if name import
  228. int HintStatus;
  229. ULONG Hint;
  230. // Forwarded name (e.g., HeapAlloc->RtlAllocateHeap)
  231. int ForwardNameStatus;
  232. CHAR ForwardName[255];
  233. // Whether this is a delayed import or not.
  234. DWORD Delayed;
  235. };
  236. // "Safely" release a COM object.
  237. template<class T>
  238. inline void SafeRelease(T& obj)
  239. {
  240. if(obj)
  241. {
  242. obj->Release();
  243. obj = 0;
  244. }
  245. }
  246. #endif //__APPPARSE_H_