/Structure Classes/PARAMDATA.ahk

http://github.com/maul-esel/COM-Classes · AutoHotKey · 106 lines · 29 code · 7 blank · 70 comment · 1 complexity · a2eda665028b0a13f8dcb58cada0e53a MD5 · raw file

  1. /*
  2. class: PARAMDATA
  3. a structure class that describes a parameter accepted by a method or property.
  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/PARAMDATA)
  10. - *msdn* (http://msdn.microsoft.com/en-us/library/windows/desktop/ms221100)
  11. Requirements:
  12. AutoHotkey - AHK v2 alpha
  13. Base classes - _CCF_Error_Handler_, StructBase
  14. Constant classes - VARENUM
  15. */
  16. class PARAMDATA extends StructBase
  17. {
  18. /*
  19. Field: szName
  20. The parameter name. Names should follow standard conventions for programming language access; that is, no embedded spaces or control characters, and 32 or fewer characters.
  21. */
  22. szName := ""
  23. /*
  24. Field: vt
  25. The parameter type. You may use the fields of the VARENUM class for convenience. If more than one parameter type is accepted, VARENUM.VARIANT should be specified.
  26. */
  27. vt := 0
  28. /*
  29. Method: constructor
  30. creates a new instance of the class
  31. Parameters:
  32. [opt] STR name - the initial value for the <szName> field.
  33. [opt] USHORT vt - the initial value for the <vt> field.
  34. */
  35. __New(name := "", vt := 0)
  36. {
  37. this.szName := name, this.vt := vt
  38. }
  39. /*
  40. Method: ToStructPtr
  41. converts the instance to a script-usable struct and returns its memory adress.
  42. Parameters:
  43. [opt] UPTR ptr - the fixed memory address to copy the struct to.
  44. Returns:
  45. UPTR ptr - a pointer to the struct in memory
  46. */
  47. ToStructPtr(ptr := 0)
  48. {
  49. if (!ptr)
  50. {
  51. ptr := this.Allocate(this.GetRequiredSize())
  52. }
  53. NumPut(this.GetAdress("szName"), 1*ptr, 00, "UPtr")
  54. NumPut(this.vt, 1*ptr, A_PtrSize, "UShort")
  55. return ptr
  56. }
  57. /*
  58. Method: FromStructPtr
  59. (static) method that converts a script-usable struct into a new instance of the class.
  60. Parameters:
  61. UPTR ptr - a pointer to a PARAMDATA struct in memory
  62. [opt] BOOL own - false if the instance must no release the pointer (defaults to true)
  63. Returns:
  64. PARAMDATA instance - the new PARAMDATA instance
  65. */
  66. FromStructPtr(ptr, own := true)
  67. {
  68. local instance := new PARAMDATA(StrGet(NumGet(1*ptr, 00, "UPtr")), NumGet(1*ptr, A_PtrSize, "UShort"))
  69. instance.SetOriginalPointer(ptr, own)
  70. return instance
  71. }
  72. /*
  73. Method: GetRequiredSize
  74. calculates the size a memory instance of this class requires.
  75. Parameters:
  76. [opt] OBJECT data - an optional data object that may contain data for the calculation.
  77. Returns:
  78. UINT bytes - the number of bytes required
  79. Remarks:
  80. - This may be called as if it was a static method.
  81. - The data object is ignored by this class.
  82. */
  83. GetRequiredSize(data := "")
  84. {
  85. return A_PtrSize + 2
  86. }
  87. }