Utilities.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // This code is the managed pdb reader interface for PERWAPI.
  3. // Written by John Gough, April 2007.
  4. // Copyright(c) 2007-2008 John Gough, and Queensland University of Technology
  5. //
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Text;
  9. using System.Runtime.InteropServices;
  10. using System.Runtime.InteropServices.ComTypes;
  11. using System.Diagnostics.SymbolStore;
  12. namespace QUT.Symbols {
  13. #region Utility Classes
  14. /// <summary>
  15. /// PInvoke hook to call COM CoCreateInstance.
  16. /// Plus any useful constants...
  17. /// </summary>
  18. internal static class OLE32 {
  19. internal const int hr_E_FAIL = unchecked((int)0x80004005);
  20. [DllImport("ole32.dll")]
  21. internal static extern int CoCreateInstance(
  22. [In] ref Guid rclsid,
  23. [In, MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
  24. [In] uint dwClsContext,
  25. [In] ref Guid riid,
  26. [MarshalAs(UnmanagedType.Interface)] out object ppv);
  27. }
  28. /// <summary>
  29. /// Some external guids, defined in cor.h, mainly
  30. /// </summary>
  31. internal static class XGuid {
  32. // This guid is the CLSID of the metadata dispenser object in mscoree.dll
  33. internal static Guid dispenserClassID = new Guid("{E5CB7A31-7512-11d2-89CE-0080C792E5D8}");
  34. // This guid is the IID of the IMetaDataDispenser interface defined in cor.h
  35. internal static Guid dispenserIID = new Guid("{809c652e-7396-11d2-9771-00a0c9b4d50c}");
  36. // This guid is the IID of the IMetaDataImport interface in cor.h
  37. internal static Guid importerIID = new Guid("{7DAC8207-D3AE-4c75-9B67-92801A497D44}");
  38. // This guid is the UUID for CorSymBinder_SxS, defined in corsym.h
  39. internal static Guid binderCLSID = new Guid("{0A29FF9E-7F9C-4437-8B11-F424491E3931}");
  40. internal static Guid binderIID = new Guid("{28AD3D43-B601-4d26-8A1B-25F9165AF9D7}");
  41. // This guid is the CLSID for CLSID_CorSymWriter_SxS, defined in corsym.h
  42. internal static Guid symWriterClassID = new Guid("0AE2DEB0-F901-478b-BB9F-881EE8066788");
  43. internal static Guid symWriterIID = new Guid("0B97726E-9E6D-4f05-9A26-424022093CAA");
  44. }
  45. [StructLayout(LayoutKind.Sequential)]
  46. public struct ImageDebugDirectory {
  47. private int Characteristics;
  48. private int TimeDateStamp;
  49. private short MajorVersion;
  50. private short MinorVersion;
  51. private int Type;
  52. private int SizeOfData;
  53. private int AddressOfRawData;
  54. private int PointerToRawData;
  55. // public override string ToString();
  56. }
  57. /// <summary>
  58. /// Some static helper methods
  59. /// </summary>
  60. internal static class Util {
  61. internal static void ComCheck(bool test, string message) {
  62. if (!test)
  63. throw new COMException(message);
  64. }
  65. internal static void ComCheckHR(int hr, string message) {
  66. if (hr == OLE32.hr_E_FAIL)
  67. throw new COMException(message);
  68. }
  69. internal static void ArgCheck(bool test, string message) {
  70. if (!test)
  71. throw new ArgumentException(message);
  72. }
  73. }
  74. #endregion // Utility Classes
  75. }