PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Structure Classes/PARAMDESC.ahk

http://github.com/maul-esel/COM-Classes
AutoHotKey | 112 lines | 30 code | 7 blank | 75 comment | 1 complexity | 1bc56476fea5e0c59244450190bfc352 MD5 | raw file
  1. /*
  2. class: PARAMDESC
  3. a structure class that contains information needed for transferring a structure element, parameter, or function return value between processes.
  4. Authors:
  5. - maul.esel (https://github.com/maul-esel)
  6. License:
  7. - *LGPL* (http://www.gnu.org/licenses/lpgl-2.1.txt)
  8. Documentation:
  9. - *class documentation* (http://maul-esel.github.com/COM-Classes/master/PARAMDESC)
  10. - *msdn* (http://msdn.microsoft.com/en-us/library/windows/desktop/ms221089)
  11. Requirements:
  12. AutoHotkey - AHK v2 alpha
  13. Base classes - _CCF_Error_Handler_, StructBase
  14. Constant classes - PARAMFLAG
  15. Structure classes - PARAMDESCEX
  16. Other classes - CCFramework
  17. */
  18. class PARAMDESC extends StructBase
  19. {
  20. /*
  21. Field: pparamdescex
  22. If PARAMFLAG.FHASDEFAULT is specified in <wParamFlags>, this is a PARAMDESCEX structure with the default value.
  23. Remarks:
  24. You may set this either to an instance of the PARAMDESCEX class or to a raw memory pointer.
  25. */
  26. pparamdescex := 0
  27. /*
  28. Field: wParamFlags
  29. The parameter flags. You may use the fields of the PARAMFLAG class for convenience.
  30. */
  31. wParamFlags := 0
  32. /*
  33. Method: constructor
  34. creates a new instance of the class
  35. Parameters:
  36. [opt] USHORT flags - the initial value for the <wParamFlags> field.
  37. [opt] PARAMDESCEX value - the initial for the <pparamdescex> field, either as memory pointer or class instance.
  38. */
  39. __New(flags := 0, value := 0)
  40. {
  41. this.flags := flags, this.value := value
  42. }
  43. /*
  44. Method: ToStructPtr
  45. converts the instance to a script-usable struct and returns its memory adress.
  46. Parameters:
  47. [opt] PTR ptr - the fixed memory address to copy the struct to.
  48. Returns:
  49. PTR ptr - a pointer to the struct in memory
  50. */
  51. ToStructPtr(ptr := 0)
  52. {
  53. if (!ptr)
  54. {
  55. ptr := this.Allocate(this.GetRequiredSize())
  56. }
  57. NumPut(this.pparamdescex.ToStructPtr(), 1*ptr, 00, "Ptr")
  58. NumPut(this.wParamFlags, 1*ptr, A_PtrSize, "UShort")
  59. return ptr
  60. }
  61. /*
  62. Method: FromStructPtr
  63. (static) method that converts a script-usable struct into a new instance of the class.
  64. Parameters:
  65. PTR ptr - a pointer to a PARAMDESC struct in memory
  66. [opt] BOOL own - false if the instance must no release the pointer (defaults to true)
  67. Returns:
  68. PARAMDESC instance - the new PARAMDESC instance
  69. */
  70. FromStructPtr(ptr, own := true)
  71. {
  72. local instance := new PARAMDESC(NumGet(1*ptr, A_PtrSize, "UShort"), PARAMDESCEX.FromStructPtr(NumGet(1*ptr, 00, "Ptr"), false))
  73. instance.SetOriginalPointer(ptr, own)
  74. return instance
  75. }
  76. /*
  77. Method: GetRequiredSize
  78. calculates the size a memory instance of this class requires.
  79. Parameters:
  80. [opt] OBJECT data - an optional data object that may contain data for the calculation.
  81. Returns:
  82. UINT bytes - the number of bytes required
  83. Remarks:
  84. - This may be called as if it was a static method.
  85. - The data object is ignored by this class.
  86. */
  87. GetRequiredSize(data := "")
  88. {
  89. static padding := A_PtrSize - 2
  90. return A_PtrSize + 2 + padding
  91. }
  92. }