ole.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package ole
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // DISPPARAMS are the arguments that passed to methods or property.
  7. type DISPPARAMS struct {
  8. rgvarg uintptr
  9. rgdispidNamedArgs uintptr
  10. cArgs uint32
  11. cNamedArgs uint32
  12. }
  13. // EXCEPINFO defines exception info.
  14. type EXCEPINFO struct {
  15. wCode uint16
  16. wReserved uint16
  17. bstrSource *uint16
  18. bstrDescription *uint16
  19. bstrHelpFile *uint16
  20. dwHelpContext uint32
  21. pvReserved uintptr
  22. pfnDeferredFillIn uintptr
  23. scode uint32
  24. }
  25. // WCode return wCode in EXCEPINFO.
  26. func (e EXCEPINFO) WCode() uint16 {
  27. return e.wCode
  28. }
  29. // SCODE return scode in EXCEPINFO.
  30. func (e EXCEPINFO) SCODE() uint32 {
  31. return e.scode
  32. }
  33. // String convert EXCEPINFO to string.
  34. func (e EXCEPINFO) String() string {
  35. var src, desc, hlp string
  36. if e.bstrSource == nil {
  37. src = "<nil>"
  38. } else {
  39. src = BstrToString(e.bstrSource)
  40. }
  41. if e.bstrDescription == nil {
  42. desc = "<nil>"
  43. } else {
  44. desc = BstrToString(e.bstrDescription)
  45. }
  46. if e.bstrHelpFile == nil {
  47. hlp = "<nil>"
  48. } else {
  49. hlp = BstrToString(e.bstrHelpFile)
  50. }
  51. return fmt.Sprintf(
  52. "wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
  53. e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
  54. )
  55. }
  56. // Error implements error interface and returns error string.
  57. func (e EXCEPINFO) Error() string {
  58. if e.bstrDescription != nil {
  59. return strings.TrimSpace(BstrToString(e.bstrDescription))
  60. }
  61. src := "Unknown"
  62. if e.bstrSource != nil {
  63. src = BstrToString(e.bstrSource)
  64. }
  65. code := e.scode
  66. if e.wCode != 0 {
  67. code = uint32(e.wCode)
  68. }
  69. return fmt.Sprintf("%v: %#x", src, code)
  70. }
  71. // PARAMDATA defines parameter data type.
  72. type PARAMDATA struct {
  73. Name *int16
  74. Vt uint16
  75. }
  76. // METHODDATA defines method info.
  77. type METHODDATA struct {
  78. Name *uint16
  79. Data *PARAMDATA
  80. Dispid int32
  81. Meth uint32
  82. CC int32
  83. CArgs uint32
  84. Flags uint16
  85. VtReturn uint32
  86. }
  87. // INTERFACEDATA defines interface info.
  88. type INTERFACEDATA struct {
  89. MethodData *METHODDATA
  90. CMembers uint32
  91. }
  92. // Point is 2D vector type.
  93. type Point struct {
  94. X int32
  95. Y int32
  96. }
  97. // Msg is message between processes.
  98. type Msg struct {
  99. Hwnd uint32
  100. Message uint32
  101. Wparam int32
  102. Lparam int32
  103. Time uint32
  104. Pt Point
  105. }
  106. // TYPEDESC defines data type.
  107. type TYPEDESC struct {
  108. Hreftype uint32
  109. VT uint16
  110. }
  111. // IDLDESC defines IDL info.
  112. type IDLDESC struct {
  113. DwReserved uint32
  114. WIDLFlags uint16
  115. }
  116. // TYPEATTR defines type info.
  117. type TYPEATTR struct {
  118. Guid GUID
  119. Lcid uint32
  120. dwReserved uint32
  121. MemidConstructor int32
  122. MemidDestructor int32
  123. LpstrSchema *uint16
  124. CbSizeInstance uint32
  125. Typekind int32
  126. CFuncs uint16
  127. CVars uint16
  128. CImplTypes uint16
  129. CbSizeVft uint16
  130. CbAlignment uint16
  131. WTypeFlags uint16
  132. WMajorVerNum uint16
  133. WMinorVerNum uint16
  134. TdescAlias TYPEDESC
  135. IdldescType IDLDESC
  136. }