HalconCOM.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*****************************************************************************
  2. * HalconCOM.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/COM
  6. * Description: Defines, types, and declarations for HALCON/COM,
  7. * required for building COM extension packages
  8. *
  9. * (c) 1996-2020 by MVTec Software GmbH
  10. * www.mvtec.com
  11. *
  12. *****************************************************************************/
  13. #ifndef HALCON_COM_H
  14. #define HALCON_COM_H
  15. #include <windows.h>
  16. #include "HIntDef.h"
  17. #include "HBase.h"
  18. #include "HDeclSpec.h"
  19. #include "HConst.h"
  20. #include "IPType.h"
  21. #include "HCtype.h"
  22. /* FindText, CreateMutex, CreateEvent, and DeleteFile are also functions of
  23. * the Windows API. They are defines on FindTextW, CreateMutexW, CreateEventW,
  24. * and DelteFileW if UNICODE is defined, otherwise they are defines on
  25. * FindTextA, CreateMutexA, CreateMutexA, and DeleteFileA.
  26. * These defines are undefined here. If you want to use the corresponding
  27. * Windows API calls, you must use FindTextA, FindTextW, CreateMutexA,
  28. * CreateMutexW, CreateEventA, CreateEventW, DeleteFileA, or DeleteFileW
  29. * directly. */
  30. #undef FindText
  31. #undef CreateMutex
  32. #undef CreateEvent
  33. #undef DeleteFile
  34. /* Error codes */
  35. #define HALCONX_ERR_BASE (0x80040000UL + 2048UL)
  36. #define HALCONX_COMINT_ERR_BASE (0x80040000UL + 1024UL)
  37. #define HXC_WRONG_INTERFACE (HALCONX_COMINT_ERR_BASE + 1UL)
  38. #define HXC_CANT_ACCESS_HANDLE (HALCONX_COMINT_ERR_BASE + 2UL)
  39. #define HXC_SRC_OBJECT_NOT_INITIALIZED (HALCONX_COMINT_ERR_BASE + 3UL)
  40. #define HXC_TUPLE_CONVERSION_ERROR (HALCONX_COMINT_ERR_BASE + 4UL)
  41. #define HXC_NULL_POINTER (HALCONX_COMINT_ERR_BASE + 5UL)
  42. #ifndef HALCON_C_H
  43. typedef Hkey Hobject; /* ID of iconic HALCON objects */
  44. typedef struct /* Tuple representation */
  45. {
  46. Hcpar *tuple;
  47. INT_PTR length;
  48. } Htuple;
  49. #define UNDEF_TYPE (-1) /* Uninitialized tuple type */
  50. #endif
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /* Prototypes of interface functions */
  55. extern LIntExport char *HMessage_COMInt(Herror message) ;
  56. extern LIntExport Herror
  57. HcomPreCall(INT proc_index, Hproc_handle *proc_handle);
  58. extern LIntExport Herror
  59. HcomCall(Hproc_handle proc_handle);
  60. extern LIntExport Herror
  61. HcomPostCall(Hproc_handle proc_handle,Herror err);
  62. extern LIntExport Herror
  63. HcomStoreIO(Hproc_handle proc_handle,INT par,Hobject inObjVar);
  64. extern LIntExport Herror
  65. HcomStoreICL(Hproc_handle proc_handle,INT par,Hlong value);
  66. extern LIntExport Herror
  67. HcomStoreICD(Hproc_handle proc_handle,INT par,double value);
  68. extern LIntExport Herror
  69. HcomStoreICT(Hproc_handle proc_handle,INT par,Htuple value);
  70. extern LIntExport Herror
  71. HcomStoreICTOOL(Hproc_handle proc_handle, INT par, Htuple value);
  72. extern LIntExport Herror
  73. HcomStoreOO(Hproc_handle proc_handle,INT par,Hobject *outObjVar,Herror err);
  74. extern LIntExport Herror
  75. HcomStoreOCL(Hproc_handle proc_handle,INT par, Hlong *outCtrlVar,Herror err);
  76. extern LIntExport Herror
  77. HcomStoreOCD(Hproc_handle proc_handle,INT par,double *outCtrlVar,Herror err);
  78. extern LIntExport Herror
  79. HcomStoreOCT(Hproc_handle proc_handle,INT par,Htuple *outCtrlVar,Herror err);
  80. extern LIntExport Herror
  81. HcomStoreOCTOOL(Hproc_handle proc_handle, INT par, Htuple *outCtrlVar,
  82. Herror err);
  83. /* Higher level signatures based on COM types */
  84. extern LIntExport Herror
  85. HcomStoreIOHandleAccess(Hproc_handle proc_handle, INT par,
  86. CComQIPtr<IHandleAccess, &IID_IHandleAccess> piha);
  87. extern LIntExport Herror
  88. HcomStoreOOHandleAccess(Hproc_handle proc_handle, INT par,
  89. CComQIPtr<IHandleAccess, &IID_IHandleAccess> piha,
  90. Herror errorStatus);
  91. extern LIntExport Herror
  92. HcomStoreITOOLHandleAccess(Hproc_handle proc_handle, INT par,
  93. CComQIPtr<IHandleAccess, &IID_IHandleAccess> piha);
  94. extern LIntExport Herror
  95. HcomStoreOTOOLHandleAccess(Hproc_handle proc_handle, INT par,
  96. CComQIPtr<IHandleAccess, &IID_IHandleAccess> piha,
  97. Herror errorStatus);
  98. extern LIntExport Herror
  99. HcomStoreICV(Hproc_handle proc_handle, INT par, VARIANT value);
  100. extern LIntExport Herror
  101. HcomStoreOCV(Hproc_handle proc_handle, INT par, VARIANT *value, Herror err);
  102. extern LIntExport Herror
  103. HcomStoreICBSTR(Hproc_handle proc_handle, INT par, BSTR value);
  104. extern LIntExport Herror
  105. HcomStoreOCBSTR(Hproc_handle proc_handle, INT par, BSTR *value, Herror err);
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. /* Conversions between tuples and COM data types */
  110. #define VARCONVERT varconvert
  111. #define TUPLECONVERT tupleconvert
  112. extern LIntExport
  113. void varconvert(Htuple *dest, const INT_PTR arg, const char *par_name);
  114. extern LIntExport
  115. void varconvert(Htuple *dest, const double arg, const char *par_name);
  116. extern LIntExport
  117. void varconvert(Htuple *dest, const BSTR arg, const char *par_name);
  118. extern LIntExport
  119. void varconvert(Hctuple *dest, const BSTR arg, const char *par_name);
  120. extern LIntExport
  121. void varconvert(Htuple *dest, const VARIANT &arg, const char *par_name);
  122. extern LIntExport
  123. void varconvert(Hctuple *dest, const VARIANT &arg, const char *par_name);
  124. extern LIntExport
  125. void tupleconvert(Htuple &val, INT_PTR *lVal, char *par_name);
  126. extern LIntExport
  127. void tupleconvert(Htuple &val, VARIANT_BOOL *bVal, char *par_name);
  128. extern LIntExport
  129. void tupleconvert(Htuple &val, double *dVal, char *par_name);
  130. extern LIntExport
  131. void tupleconvert(Htuple &val, BSTR *bstrVal, char *par_name);
  132. extern LIntExport
  133. void tupleconvert(Hctuple *val, BSTR *bstrVal, char *par_name);
  134. extern LIntExport
  135. void tupleconvert(Htuple &val, VARIANT *varVal, char *par_name);
  136. extern LIntExport
  137. void tupleconvert(Hctuple *val, VARIANT *varVal, char *par_name);
  138. class ConversionException
  139. {
  140. public:
  141. char *msg;
  142. ConversionException(char *m)
  143. {
  144. msg = ::new char [strlen(m)+1];
  145. strcpy(msg, m);
  146. }
  147. ConversionException(const ConversionException &src)
  148. {
  149. msg = ::new char [strlen(src.msg)+1];
  150. strcpy(msg, src.msg);
  151. }
  152. ~ConversionException(void)
  153. {
  154. delete [] msg;
  155. }
  156. };
  157. /* Macros for storing object parameters */
  158. #define HCOMSTOREIO(INDEX,NAME) \
  159. if (NAME == NULL) \
  160. errorStatus = HXC_NULL_POINTER - HALCONX_ERR_BASE; \
  161. else \
  162. { \
  163. CComQIPtr<IHandleAccess, &IID_IHandleAccess> piha(NAME); \
  164. errorStatus = HcomStoreIOHandleAccess(ph,INDEX,piha); \
  165. }
  166. #ifndef HALCON_COM_INTERNAL_H
  167. #define HCOMSTOREOO(INDEX,NAME,TYPE) \
  168. CComQIPtr<I##TYPE, &IID_I##TYPE> p##NAME; \
  169. p##NAME.CoCreateInstance(L"HalconX." L#TYPE); \
  170. CComQIPtr<IHandleAccess, &IID_IHandleAccess> pi##NAME(p##NAME); \
  171. errorStatus = HcomStoreOOHandleAccess(ph,INDEX,pi##NAME,errorStatus); \
  172. p##NAME->QueryInterface(IID_I##TYPE, (void**)NAME)
  173. #endif
  174. #endif