home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / ocfinc.pak / AUTODEFS.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  61KB  |  1,482 lines

  1. //
  2. //----------------------------------------------------------------------------
  3. // ObjectComponents
  4. // (C) Copyright 1994 by Borland International, All Rights Reserved
  5. //
  6. //   OLE Automation Class Definitions
  7. //----------------------------------------------------------------------------
  8. #if !defined(OCF_AUTODEFS_H)
  9. #define OCF_AUTODEFS_H
  10.  
  11. #if !defined(OCF_OCDEFS_H)
  12. #  include <ocf/ocdefs.h>
  13. #endif
  14. #if !defined(OSL_LOCALE_H)
  15. # include <osl/locale.h>   // TLocaleString and TRegItem/TRegList
  16. #endif
  17. #if !defined(OSL_USTRING_H)
  18. # include <osl/ustring.h>  // TString and TUString
  19. #endif
  20. #if !defined(__TYPEINFO_H)
  21. # include <typeinfo.h>
  22. #endif
  23.  
  24. // class modifier for inherited classes or members within user C++ classes
  25. // if ambient class model is not used, this macro must be defined to match
  26. //
  27. #if !defined(_AUTOCLASS)
  28. # define  _AUTOCLASS
  29. #endif
  30.  
  31. // forward class references
  32. //
  33. class _AUTOCLASS TAutoDetach;
  34. class _AUTOCLASS TAutoBase;
  35. class _ICLASS TAppDescriptor;  // defined in appdesc.h
  36. class _ICLASS TServedObject;
  37. class _ICLASS TAutoIterator;
  38. class TAutoCreator;
  39. class TAutoCommand;
  40. class TAutoSymbol;
  41. class TAutoString;
  42. class TAutoStack;
  43. class far TAutoVal;
  44. class TXAuto;
  45. class TAutoEnum;
  46.  
  47. const void far* DynamicCast(const void far* obj, const typeinfo& src,
  48.                                                  const typeinfo& dst);
  49. const void far* MostDerived(const void far* obj, const typeinfo& src);
  50.  
  51. // global function to invalidate external references, class model-independent
  52. //
  53. void SendObituary(const void far* obj, const typeinfo& typeInfo);
  54.  
  55. //____________________________________________________________________________
  56. //
  57. // Automation typedefs
  58. //____________________________________________________________________________
  59.  
  60. typedef unsigned long TLocaleId;   // locale ID - same as NT LCID
  61.  
  62. class _AUTOCLASS TAutoBase {   // default base for automatable objects
  63.   public:
  64.     virtual ~TAutoBase();// only member is virtual destructor for unregistration
  65. };
  66.  
  67. class _AUTOCLASS TAutoDetach { // default base for detach notification objects
  68.   protected:
  69.     void Notify(int offset, const typeinfo& typeInfo);  // sends obituary
  70. };          // the size of this object must be 0 to not affect enclosing class
  71.  
  72. typedef void* ObjectPtr;  // generic opaque object pointer
  73.  
  74. // Generic conversion function for changing between inherited classes
  75.  
  76. template <class T, class B> struct TTypeConvert {
  77.   static ObjectPtr Cast(ObjectPtr from) { return
  78.    reinterpret_cast<ObjectPtr>( dynamic_cast<T*>(reinterpret_cast<B*>(from)));
  79.   }
  80. };
  81.  
  82. typedef ObjectPtr      (*TAutoSymTypeConvert) (ObjectPtr obj);
  83. typedef TAutoCommand*  (*TAutoCommandBuild)(ObjectPtr obj,int attr,TAutoStack&);
  84. typedef TAutoCommand*  (*TAutoCommandBuildDtr)(ObjectPtr obj, int attr);
  85. typedef TAutoIterator* (*TAutoIteratorBuild)(ObjectPtr obj,
  86.                                              TAutoCreator& creator,
  87.                                              IUnknown* owner, TLangId lang);
  88. typedef IUnknown&      (*TAggregator)(ObjectPtr obj, TUnknown& inner);
  89.  
  90. extern "C" const GUID __cdecl IID_TServedObject;
  91.  
  92. //____________________________________________________________________________
  93. //
  94. // TXAuto - automation exception object
  95. //____________________________________________________________________________
  96.  
  97. class TXAuto : public TXBase {
  98.   public:
  99.     enum TError {
  100.       xNoError,
  101.       xConversionFailure,
  102.       xNotIDispatch,
  103.       xForeignIDispatch,
  104.       xTypeMismatch,
  105.       xNoArgSymbol,
  106.       xParameterMissing,
  107.       xNoDefaultValue,
  108.       xValidateFailure,
  109.       xExecutionFailure,
  110.       xErrorStatus,
  111.     };
  112.     TXAuto(TXAuto::TError err)
  113.         : TXBase("Automation Exception"), ErrorCode(err) {}
  114.     TError ErrorCode;
  115. };
  116.  
  117. //____________________________________________________________________________
  118. //
  119. // TAutoType, TAutoClass - automation type/class descriptor
  120. //____________________________________________________________________________
  121.  
  122. struct TAutoType {
  123.     uint16 GetType() const {return Type;}
  124.     uint16 Type;
  125. };
  126.  
  127. class TAutoClass : public TAutoType {
  128.   public:
  129.     TAutoClass(TAutoSymbol* table, TAutoSymbol* classSymbol,
  130.                const typeinfo& typeInfo, TAggregator aggregator=0);
  131.    ~TAutoClass();
  132.  
  133.     short         CountCommands();    // forces counts to be set on first call
  134.     TAutoSymbol*  Lookup(char far* name, TLangId lang, short symFlags, long far& id);
  135.     TAutoSymbol*  LookupArg(char far* name, TLangId lang, TAutoSymbol* cmd,
  136.                             long far& retid);
  137.     TAutoSymbol*  FindId(short id, ObjectPtr& objptr);
  138.     TAutoSymbol*  FindFunction(unsigned index, int& retId);
  139.     TAutoSymbol*  FindVariable(unsigned index, int& retId);
  140.     TXAuto::TError Dispatch(ObjectPtr obj, TAutoCreator& creator,
  141.                             TUnknown& owner, int attr, TAutoStack& args,
  142.                             TAutoVal far* retval);
  143.     TAutoSymbol*  GetTable();
  144.     TAutoSymbol*  GetClassSymbol();
  145.     short         GetArgCount(TAutoSymbol& sym);
  146.     TAutoCommandBuildDtr GetDestructor();
  147.     const typeinfo&  GetTypeInfo();
  148.     const char* GetName(TLangId lang = TLocaleString::UserDefaultLangId);
  149.     const char* GetDoc (TLangId lang = TLocaleString::UserDefaultLangId);
  150.     unsigned long GetHelpId();
  151.     unsigned short GetTypeFlags();
  152.     int            GetImplTypeFlags();
  153.     unsigned short GetCoClassFlags();
  154.     TAggregator GetAggregator();
  155.     IUnknown&   Aggregate(ObjectPtr obj, TUnknown& inner);
  156.  
  157.   protected:
  158.     TAggregator Aggregator;  // aggregator function for C++ COM classes
  159.     short CommandCount;      // command count including bases, 0 if uncounted
  160.     short FunctionCount;     // number of symbols exposed as typelib functions
  161.     short VariableCount;     // number of symbols exposed as typelib variables
  162.     TAutoSymbol* Table;      // pointer to array of symbol entries
  163.     TAutoSymbol* ClassSymbol;// pointer to class symbol (terminator)
  164.     const typeinfo& TypeInfo;// for validating type of data pointers
  165.     friend class TServedObject;
  166.  
  167.   private:
  168.     struct TAutoClassRef {   // element used for array of TAutoClass objects
  169.       TAutoClass* Class;
  170.       int         GuidOffset;
  171.     };
  172.     struct TExtLink;      // fwd declaration
  173.     static struct TClassList { // module-static TAutoClass data
  174.       int  CountAutoClasses();  // walks list in attatched DLLs
  175.       TAutoClassRef* MergeAutoClasses(TAutoClassRef* array);
  176.       TAutoClass* List;   // chain of autoclasses in THIS module
  177.       int         Count;  // count of classes in THIS module
  178.       TExtLink*   Link;   // chain of TAutoClass data for loaded DLLs
  179.     } ClassList;
  180.     struct TExtLink {      // doubly-linked list of external DLL data
  181.       TExtLink(TClassList* list, HINSTANCE module);
  182.      ~TExtLink();
  183.       TClassList* Classes;
  184.       HINSTANCE   Module; // module handle if dynmaically loaded, else 0
  185.       TExtLink*   Next;
  186.       TExtLink**  Prev;
  187.     };
  188.     TAutoClass*   NextClass;          // link to next class
  189.     friend class TExtLink;            // access to ClassList
  190.     friend class TClassList;          // access to TAutoClassRef
  191.     friend class _ICLASS TTypeLibrary;// access to TAutoClassRef
  192.     friend class _ICLASS TCoClassInfo;// access to TAutoClassRef
  193.     friend class TAppDescriptor;      // access to linkage information
  194. };
  195.  
  196. //____________________________________________________________________________
  197. //
  198. // TAuto(type) automation datatype encapsulations
  199. //____________________________________________________________________________
  200.  
  201. struct TAutoVoid {  // purpose to implement assignent of void to TAutoVal
  202.   static TAutoType ClassInfo;
  203. };
  204.  
  205. struct TAutoDate {  // purpose to disambiguate type from double
  206.   TAutoDate() : Date(0) {}
  207.   TAutoDate(double d) : Date(d) {}
  208.   operator double() { return Date; }
  209.   double Date;      // same as OLE DATE
  210.   static TAutoType ClassInfo;
  211. };
  212.  
  213. struct TAutoCurrency : public CY {
  214.   static TAutoType ClassInfo;
  215. };
  216.  
  217. struct TAutoBool {  // for suppressing compiler warnings until bool is a type
  218.   TAutoBool() : B(0) {}
  219.   TAutoBool(bool b) : B(b) {}
  220.   TAutoBool(TBool b) : B(static_cast<bool>(b)) {}
  221.   operator bool() {return B;}
  222.   operator TBool() {return static_cast<TBool>(B);}
  223.   void operator =(bool b) {B = b;}
  224.   void operator =(TBool b) {B = static_cast<bool>(b);}
  225.   bool B;
  226.   static TAutoType ClassInfo;
  227. };
  228.  
  229. struct TAutoBoolRef {  // needed for automating bool far* until bool is a type
  230.   TAutoBoolRef() : P(0) {}
  231.   TAutoBoolRef(bool far* p) : P(p) {}
  232.   TAutoBoolRef(TBool far* p) : P((bool far*)p) {}
  233.   operator bool far*() {return P;}
  234.   void operator =(bool far* p) {P = p;}
  235.   void operator =(TBool far* p){P = (bool far*)p;}
  236.   bool far* P;
  237.   static TAutoType ClassInfo;
  238. };
  239.  
  240. // the following types do no hold data, but only provide static type codes
  241.  
  242. struct TAutoShort      { static TAutoType ClassInfo; };
  243. struct TAutoDouble     { static TAutoType ClassInfo; };
  244. struct TAutoFloat      { static TAutoType ClassInfo; };
  245. struct TAutoLong       { static TAutoType ClassInfo; };
  246. struct TAutoByte       { static TAutoType ClassInfo; };
  247. struct TAutoUnknown    { static TAutoType ClassInfo; };  // for raw IUnknown*
  248. struct TAutoDispatch   { static TAutoType ClassInfo; };  // for raw IDispatch*
  249. struct TAutoShortRef   { static TAutoType ClassInfo; };
  250. struct TAutoLongRef    { static TAutoType ClassInfo; };
  251. struct TAutoFloatRef   { static TAutoType ClassInfo; };
  252. struct TAutoDoubleRef  { static TAutoType ClassInfo; };
  253. struct TAutoCurrencyRef{ static TAutoType ClassInfo; };
  254. struct TAutoDateRef    { static TAutoType ClassInfo; };
  255. struct TAutoStringRef  { static TAutoType ClassInfo; };
  256. struct TAutoVariantRef { static TAutoType ClassInfo; };
  257. struct TAutoByteRef    { static TAutoType ClassInfo; };
  258. #if (MAXINT==MAXSHORT)
  259. typedef TAutoShort    TAutoInt;
  260. typedef TAutoShortRef TAutoIntRef;
  261. #else
  262. typedef TAutoLong    TAutoInt;
  263. typedef TAutoLongRef TAutoIntRef;
  264. #endif
  265.  
  266. //____________________________________________________________________________
  267. //
  268. // Attribute flags for automation symbols and command objects
  269. //____________________________________________________________________________
  270.  
  271. enum AutoSymFlag {
  272.   asAnyCommand     = 0x0017,  // any command: method, property get/set, build
  273.    asOleType       = 0x0007,  // method or property exposed for OLE
  274.     asMethod       = 0x0001,  // method     (same as OLE INVOKE_FUNC)
  275.     asGet          = 0x0002,  // returns property value (INVOKE_PROPERTYGET)
  276.      asIterator    = 0x000A,  // iterator property (_NewEnum)
  277.     asSet          = 0x0004,  // set property value     (INVOKE_PROPERTYSET)
  278.     asGetSet       = 0x0006,  // can get or set property(...GET + ...SET)
  279.    asBuild         = 0x0010,  // contructor command (unsupported by OLE 2.01)
  280.   asFactory        = 0x0020,  // for creating objects or class determination
  281.   asClass          = 0x0040,  // extension to another class symbol table
  282.   asArgument       = 0x0080,  // property returning an object
  283.   asNotTerminator  = 0x00FF,  // any symbol except terminator with class info
  284.  
  285.   asBindable       = 0x0400,  // sends OnChanged notification
  286.   asRequestEdit    = 0x0800,  // sends OnRequest edit before change
  287.   asDisplayBind    = 0x1000,  // user-display of bindable
  288.   asDefaultBind    = 0x2000,  // this property only is the default (redundant)
  289.   asHidden         = 0x4000,  // not visible to normal browsing
  290.   asPersistent     = 0x8000,  // property is persistent
  291. };
  292.  
  293. // Automation datatypes and flags - same as OLE 2 definitions
  294.  
  295. enum AutoDataType {
  296.   atVoid              = 0x0000,   //  void
  297.   atNull              = 0x0001,   //  SQL style Null
  298.   atShort             = 0x0002,   //  2 byte signed int
  299.   atLong              = 0x0003,   //  4 byte signed int
  300.   atFloat             = 0x0004,   //  4 byte real
  301.   atDouble            = 0x0005,   //  8 byte real
  302.   atCurrency          = 0x0006,   //  currency
  303.   atDatetime          = 0x0007,   //  datetime as double
  304.   atString            = 0x0008,   //  BSTR, string preceeded by length
  305.   atObject            = 0x0009,   //  IDispatch*
  306.   atError             = 0x000A,   //  SCODE
  307.   atBool              = 0x000B,   //  True=-1, False=0
  308.   atVariant           = 0x000C,   //  VARIANT FAR*
  309.   atUnknown           = 0x000D,   //  IUnknown*
  310.   atByte              = 0x0011,  //  byte, unsigned char
  311.   atObjectDesc        = 0x001D,   //  object precursor state (internal use only)
  312.   atLoanedBSTR        = 0x001A,   //  BSTR owned by TUString (internal use only)
  313.   atTypeMask          = 0x001F,   //  base type code without bit flags
  314.   atOLE2Mask          = 0x601F,   //  type code with bit flags
  315. };
  316. const uint16 atSafeArray = 0x2000;
  317. const uint16 atByRef     = 0x4000;
  318. const uint16 atEnum      = 0x1000;   // non-OLE, enumeration for data of a type
  319. const uint16 atAutoClass = 0x0800;   // non-OLE, class object is a TAutoClass
  320.  
  321. //____________________________________________________________________________
  322. //
  323. // Automated class typeinfo flags - corresponding to OLE 2.02 definitions
  324. //    flags set in END_AUTOCLASS, END_AUTOAGGREGATE, END_AUTOEVENTCLASS macros
  325. //____________________________________________________________________________
  326.  
  327. // Flags set on any autoclass, but apply only to enclosing coclass typeinfo.
  328. // Autoclasses with any of these bits set will be members of generated coclass.
  329. // These flags from all autoclasses are combined to form the coclass type flags
  330.  
  331. const uint16 tfAppObject     =   1; // TYPEFLAG_FAPPOBJECT, set on COCLASS
  332. const uint16 tfCanCreate     =   2; // TYPEFLAG_FCANCREATE, set on COCLASS
  333. const uint16 tfLicensed      =   4; // TYPEFLAG_FLICENSED,  set on COCLASS
  334. const uint16 tfPredeclared   =   8; // TYPEFLAG_FPREDECLID, set on COCLASS
  335. const uint16 tfControl       =  32; // TYPEFLAG_FCONTROL,   set on COCLASS
  336. const uint16 tfCoClassXfer   =  tfAppObject|tfCanCreate|tfLicensed|tfControl|tfPredeclared;
  337.  
  338. // Flags set on any autoclass, but used when class is a member of a coclass.
  339. // Autoclasses with any of these bits set will be members of generated coclass.
  340. // Flags from each class are set on the corresponding interfaces in the coclass
  341.  
  342. const uint16 tfDefault      = (1<<12); // IMPLTYPEFLAG_FDEFAULT << 12
  343. const uint16 tfEventSource  = (2<<12); // IMPLTYPEFLAG_FSOURCE << 12
  344. const uint16 tfRestricted   = (4<<12); // IMPLTYPEFLAG_FRESTRICTED << 12
  345. const uint16 tfImplFlagXfer = (tfDefault | tfEventSource | tfRestricted);
  346.  
  347. // Flags set on individual autoclasses, transferred to corresponding typeinfos
  348.  
  349. const uint16 tfHidden        =  16;  // TYPEFLAG_FHIDDEN
  350. const uint16 tfNonextensible = 128;  // TYPEFLAG_FNONEXTENSIBLE
  351. const uint16 tfAutoClassMask =  tfHidden|tfNonextensible;
  352.  
  353. // Flags defined by OLE, but not applicable to dispatch interfaces
  354.  
  355. const uint16 tfDual          =  64;  // TYPEFLAG_FDUAL
  356. const uint16 tfAutomation    = 256;  // TYPEFLAG_FOLEAUTOMATION
  357.  
  358. // Default typeflags value for autoclass not exposed as part of the coclass
  359.  
  360. const uint16 tfNormal        =   0;  // automated classes not at app level
  361.  
  362. //____________________________________________________________________________
  363. //
  364. //  TAutoSymbol - symbol table element
  365. //____________________________________________________________________________
  366.  
  367. struct TAutoSymbol {
  368.   TLocaleString Name;         // name of symbol, initially untranslated
  369.   TLocaleString Doc;          // documentation string, initially untranslated
  370.   uint16 Attr;                // attributes: enum AutoSymFlag, as????
  371.   union {
  372.     short DispId;             // reserved dispatch ID, if not 0
  373.     short SymCount;           // asClass only: symbol count, 0 = uncounted yet
  374.     unsigned short TypeFlags; // class symbol only (terminator)
  375.   };
  376.   TAutoType* Type;             // pointer to class/type/enum descriptor
  377.   union {
  378.     TAutoCommandBuild  Build;  // asAnyCommand only: address of command builder
  379.     TAutoIteratorBuild BuildIter;// asIterator only: address of iterator builder
  380.     TAutoSymTypeConvert Convert; // asFactory/asClass: function to perform cast
  381.     TAutoCommandBuildDtr BuildDtr;// terminator only: destructor command builder
  382.     void far*      DefaultArg; // asArgument: default value, extends to 8 bytes
  383.   };
  384.   ulong HelpId;              // help context ID, not for asArgument
  385.  
  386.   // inline data member accessor functions
  387.   void SetFlag(uint16 mask);
  388.   void ClearFlag(uint16 mask);
  389.   bool TestFlag(uint16 mask);
  390.   uint16 GetFlags();
  391.   bool IsEnum();
  392.   bool IsByRef();
  393.   bool IsArray();
  394.   bool IsIterator();
  395.   bool IsTerminator();
  396.   uint16 GetDataType();
  397.   TAutoClass*  GetClass();
  398.   TAutoEnum*   GetEnum();
  399.  
  400.   // inline static functions solely to provide type-safety initializing symbols
  401.   static TAutoCommandBuild InitTypeConvert(TAutoSymTypeConvert f);
  402.   static TAutoCommandBuild InitAutoIterator(TAutoIteratorBuild f);
  403.   static TAutoCommandBuild InitAutoDestructor(TAutoCommandBuildDtr f);
  404. };
  405.  
  406. //____________________________________________________________________________
  407. //
  408. // TObjectDescriptor - precursor to TServedObject containing object info
  409. //____________________________________________________________________________
  410.  
  411. struct TObjectDescBase {   // ONLY for use when storing in TAutoVal union
  412.   const void* Object;      // pointer to C++ object
  413.   TAutoClass* Class;       // class descriptor, contains typeinfo
  414.   const void far* MostDerived()
  415.                          {return ::MostDerived(Object, Class->GetTypeInfo());}
  416. };  // cannot have a constructor and must limit to 8 bytes for TAutoVal union
  417.  
  418. struct TObjectDescriptor : public TObjectDescBase {
  419.   enum TDestruct     { // behavior when an automation helper is freed
  420.     Quiet = 0,         // automation object quietly goes away without notice
  421.     Delete = 1,        // automation object deletes the C++ object serviced
  422.     PostQuit = 2       // automation object posts a quit message to application
  423.   };
  424.   TDestruct Destruct;
  425.   TObjectDescriptor(const void* obj, TAutoClass& classobj,
  426.                     TObjectDescriptor::TDestruct destruct = Quiet)
  427.                     { Object = obj; Class = &classobj; Destruct = destruct; }
  428.   private:
  429.     TObjectDescriptor() {}    // uninitialized struct
  430.   friend class TAutoClass;    // restrict access to uninitialized constructor
  431.   friend class TAutoIterator;
  432. };
  433.  
  434. //____________________________________________________________________________
  435. //
  436. // TAutoVal - automation data element (same data as OLE/BASIC VARIANT)
  437. //____________________________________________________________________________
  438.  
  439. // This class simply duplicates and adds access methods to the system VARIANT
  440. // Data members or virtual functions cannot be added.
  441. // We rely on the fact that we can cast a VARIANT safely to/from a TAutoVal.
  442.  
  443. class far TAutoVal {
  444.   public:
  445.     operator unsigned char();
  446.     operator signed char();
  447.     operator char();
  448.     operator unsigned char far*();
  449.     operator signed char far*();
  450.     operator char far*();
  451.     operator int();
  452.     operator int far*();
  453.     operator unsigned int();
  454.     operator short();
  455.     operator short far*();
  456.     operator unsigned short();
  457.     operator unsigned short far*();// Note:VARIANT can't distinguish from short*
  458.     operator long();
  459.     operator long far*();
  460.     operator unsigned long();
  461.     operator unsigned long far*();// Note:VARIANT can't distinguish from long*
  462.     operator float();
  463.     operator float far*();
  464.     operator double();
  465.     operator double far*();
  466.     operator TBool();
  467.     operator TBool far*();
  468.     operator TAutoBool();
  469.     operator TAutoBoolRef();
  470.     operator TAutoCurrency();
  471.     operator TAutoCurrency far*();
  472.     operator TAutoDate();
  473.     operator TAutoDate far*();
  474.     operator string();
  475.     operator TUString*();
  476.     operator IDispatch*();
  477.     operator IUnknown*();
  478.     operator IDispatch&();
  479.     operator IUnknown&();
  480.  
  481.     void operator =(unsigned char      i);
  482.     void operator =(signed char        i);
  483.     void operator =(char               i);
  484.     void operator =(unsigned char far* p);
  485.     void operator =(signed char far*   p);
  486.     void operator =(char far*          p);
  487.     void operator =(int                i);
  488.     void operator =(int far*           p);
  489.     void operator =(unsigned int       i);
  490.     void operator =(unsigned int far*  p);
  491.     void operator =(unsigned short     i);
  492.     void operator =(unsigned short far*p);
  493.     void operator =(long               i);
  494.     void operator =(long far*          p);
  495.     void operator =(unsigned long      i);
  496.     void operator =(unsigned long far* p);
  497.     void operator =(short              i);
  498.     void operator =(short far*         p);
  499.     void operator =(float              i);
  500.     void operator =(float far*         p);
  501.     void operator =(double             i);
  502.     void operator =(double far*        p);
  503.     void operator =(TBool              i);
  504.     void operator =(TBool far*         p);
  505.     void operator =(TAutoBool          i);
  506.     void operator =(TAutoBoolRef       p);
  507.     void operator =(const string&      s);
  508.     void operator =(TAutoString        s);
  509.     void operator =(TAutoCurrency      i);
  510.     void operator =(TAutoCurrency far* p);
  511.     void operator =(TAutoDate          i);
  512.     void operator =(TAutoDate far*     i);
  513.     void operator =(IDispatch*       ifc);
  514.     void operator =(IUnknown*        ifc);
  515.     void operator =(TObjectDescriptor od);
  516.     void operator =(TAutoVoid);
  517.  
  518.     int GetDataType();
  519.     void Clear();      // free any references, set type to atVoid
  520.     void Restore();    // convert any non-OLE changes back to original types
  521.     void Copy(const TAutoVal& copy);
  522.     bool IsRef();
  523.     TAutoVal far* DereferenceVariant();
  524.     void SetLocale(TLocaleId);  // associate locale with appropriate pointers
  525.     TLocaleId GetLocale() const;// retrieve locale from appropriate pointers
  526.     TLangId   GetLanguage() const; // retrieve language from pointer types
  527.     TString   StrVal();   // returns internal string pointer if atString
  528.     bool GetObjDesc(TObjectDescriptor&);// return temp object info, else false
  529.     SAFEARRAY far* GetArray();   // return array pointer, null if not array
  530.     void far* SetByRef(AutoDataType);  // set type, return pointer to data loc
  531.  
  532.   private:
  533.     unsigned short vt;
  534.     unsigned short Reserved1;
  535.     unsigned short Reserved2;
  536.     unsigned short Reserved3;
  537.     union {
  538.       unsigned char bVal;             // VT_UI1
  539.       short         iVal;             // VT_I2
  540.       long          lVal;             // VT_I4
  541.       float         fltVal;           // VT_R4
  542.       double        dblVal;           // VT_R8
  543.       VARIANT_BOOL  boolVal;          // VT_BOOL
  544.       SCODE         scode;            // VT_ERROR
  545.       TAutoCurrency cyVal;            // VT_CY
  546.       DATE          date;             // VT_DATE
  547.       BSTR          bstrVal;          // VT_BSTR
  548.       IUnknown*     punkVal;          // VT_UNKNOWN
  549.       IDispatch*    pdispVal;         // VT_DISPATCH
  550.       SAFEARRAY far* parray;          // VT_ARRAY|*
  551.  
  552.       unsigned char far* pbVal;       // VT_BYREF|VT_UI1
  553.       short         far* piVal;       // VT_BYREF|VT_I2
  554.       long          far* plVal;       // VT_BYREF|VT_I4
  555.       float         far* pfltVal;     // VT_BYREF|VT_R4
  556.       double        far* pdblVal;     // VT_BYREF|VT_R8
  557.       VARIANT_BOOL  far* pbool;       // VT_BYREF|VT_BOOL
  558.       SCODE         far* pscode;      // VT_BYREF|VT_ERROR
  559.       TAutoCurrency far* pcyVal;      // VT_BYREF|VT_CY
  560.       DATE          far* pdate;       // VT_BYREF|VT_DATE
  561.       BSTR          far* pbstrVal;    // VT_BYREF|VT_BSTR
  562.       IUnknown*     far* ppunkVal;    // VT_BYREF|VT_UNKNOWN
  563.       IDispatch*    far* ppdispVal;   // VT_BYREF|VT_DISPATCH
  564.       SAFEARRAY far* far* pparray;    // VT_BYREF|VT_ARRAY|*
  565.       VARIANT       far* pvarVal;     // VT_BYREF|VT_VARIANT
  566.       void          far* byref;       // Generic ByRef
  567.  
  568.       struct {                       // added locale info for BSTR/IDispatch
  569.         void far* Val;
  570.         LCID      Locale;            // unused 4 bytes for pointer types
  571.       } p;
  572.  
  573.       struct {                       // added info when loaned BSTR ownership
  574.         BSTR      Val;
  575.         TUString* Holder;            // string holder sharing current BSTR
  576.       } s;
  577.  
  578.       TObjectDescBase ObjDesc;       // temporary space for returning object
  579.     };
  580.     void ConvRef(int type);
  581. };
  582.  
  583. //____________________________________________________________________________
  584. //
  585. // TAutoString class - based on reference counted TString with added automation
  586. //   functionality
  587. //
  588. class TAutoString : public TString {
  589.   public:
  590.     TAutoString(const char far* s = 0) : TString(s) {}
  591. #if defined(BI_HAS_WCHAR)
  592.     TAutoString(const wchar_t* s)      : TString(s) {}
  593. #endif
  594.     TAutoString(BSTR s, bool loan)     : TString(s) {}
  595.     TAutoString(const string& s)       : TString(s) {}
  596.     TAutoString(TUString* s)           : TString(s) {}
  597.     TAutoString(TAutoVal& val)         : TString(val) {}
  598.     TAutoString(const TAutoString& src) : TString(src.S) {++*S;}
  599.  
  600.     TAutoString& operator =(const char far* s) {S = S->Assign(s); return *this;}
  601.     TAutoString& operator =(const TAutoString& s) {S = S->Assign(*s.S); return *this;}
  602.     TAutoString& operator =(char* s)           {S = S->Assign(s); return *this;}
  603. #if defined(BI_HAS_WCHAR)
  604.     TAutoString& operator =(const wchar_t* s)  {S = S->Assign(s); return *this;}
  605.     TAutoString& operator =(wchar_t* s)        {S = S->Assign(s); return *this;}
  606. #endif
  607.     TAutoString& operator =(TAutoVal& val)     {--*S; S = val; return *this;}
  608.  
  609.     static TAutoType ClassInfo;              // automation type code
  610. };
  611.  
  612. //____________________________________________________________________________
  613. //
  614. // TAutoStack - automation argument stack abstraction
  615. //____________________________________________________________________________
  616.  
  617. class TAutoStack {
  618.   public:
  619.     enum {SetValue = -3}; // special arg index for property set value
  620.     TAutoStack(VARIANT far* stack, TLocaleId locale, int argcount,
  621.                int namedcount, long far* map, TServedObject* owner);
  622.    ~TAutoStack();
  623.     TAutoVal& operator[](int index);
  624.     TAutoSymbol* Symbol;      // symbol of method/prop, args follow
  625.     int ArgSymbolCount;
  626.     TLangId LangId;
  627.     int CurrentArg;           // index of last arg requested by operator[]
  628.     const int ArgCount;
  629.     TServedObject* Owner;
  630.     long ErrorCode;           // set if TXAuto::xErrorStatus returned
  631.     const char* ErrorMsg;     // set if TXAuto::xErrorStatus returned
  632.   protected:
  633.     TAutoVal far* Stack;
  634.     int NamedCount;
  635.     long far* NamedIds;
  636.     TAutoVal Default;
  637. };
  638.  
  639. //____________________________________________________________________________
  640. //
  641. // Automation abstract base class for command objects
  642. //____________________________________________________________________________
  643.  
  644. struct TAutoTransfer;              // persistence transfer parameter structure
  645.  
  646. class TAutoCommand {
  647.   public:
  648.     TAutoCommand(int attr);          // construtor called from derived classes
  649.     virtual ~TAutoCommand() {}
  650.     virtual TAutoCommand* Undo();             // generate command for undo stack
  651.     virtual int           Record(TAutoStack& q); // record command and arguments
  652.     virtual TAutoCommand& Invoke();           // invoke all command processing
  653.     virtual bool          Validate();         // validate parameters
  654.     virtual void          Execute();          // perform action on C++ object
  655.     virtual long          Report();           // check result of execution
  656.     virtual void          Return(TAutoVal& v);// convert return value to variant
  657.     virtual void          Transfer(TAutoTransfer& x); // stream data in or out
  658.             void          Fail(TXAuto::TError);// throw designated exception
  659.  
  660.     // Non-virtual hook functions
  661.     typedef const char* (*TErrorMsgHook)(long errCode);
  662.     static TErrorMsgHook SetErrorMsgHook(TErrorMsgHook callback);
  663.  
  664.     typedef bool (*TCommandHook)(TAutoCommand& cmdObj);
  665.     static TCommandHook SetCommandHook(TCommandHook callback);
  666.  
  667.     // inline data member accessor functions
  668.     static const char* LookupError(long errCode);
  669.     void SetFlag(int mask);
  670.     void ClearFlag(int mask);
  671.     bool TestFlag(int mask);
  672.     bool IsPropSet();
  673.     TAutoSymbol* GetSymbol();
  674.     void SetSymbol(TAutoSymbol* sym);
  675.  
  676.   protected:
  677.     TAutoSymbol* Symbol;      // symbol entry generating this command
  678.     int Attr;                 // attribute and state flags, asXXXXXX
  679. };
  680.     extern TAutoCommand::TErrorMsgHook TAutoCommand_ErrorLookup;
  681.     extern TAutoCommand::TCommandHook  TAutoCommand_InvokeHook;
  682.  
  683. // Build function for application Quit command implementation
  684. TAutoCommand* AutoQuitBuild(ObjectPtr obj, int attr, TAutoStack& args);
  685.  
  686. //____________________________________________________________________________
  687. //
  688. // TAutoEnum - automation enumeration descriptor
  689. //____________________________________________________________________________
  690.  
  691. template <class T>
  692. struct TAutoEnumVal {
  693.   TLocaleString Name;         // name of symbol, enumeration text
  694.   T Val;                      // enumeration internal value
  695. };
  696.  
  697. class TAutoEnum : public TAutoType {
  698.   public:
  699.     virtual bool Convert(TAutoVal& txtVal, TAutoVal& numVal) = 0;
  700.     virtual bool Convert(TAutoVal& numVal, TLangId langId) = 0;
  701.  
  702.   protected:
  703.     TAutoEnum(int count, int type);
  704.     int Count;              // length of this symbol table
  705. };
  706.  
  707. template <class T>
  708. class TAutoEnumT : public TAutoEnum {
  709.   public:
  710.     TAutoEnumT(TAutoEnumVal<T>* table, int symcount, int type);
  711.     bool Convert(TAutoVal& txtVal, TAutoVal& numVal);
  712.     bool Convert(TAutoVal& numVal, TLangId langId);
  713.  
  714.   protected:
  715.     TAutoEnumVal<T>* Table; // pointer to array of symbol entries
  716. };
  717.  
  718. //____________________________________________________________________________
  719. //
  720. // TAutoCreator - Object responsible for creating automation COM object
  721. //____________________________________________________________________________
  722.  
  723. class TAutoCreator {
  724.   public:
  725.     TAutoCreator() {}
  726.     virtual TUnknown*  CreateObject(TObjectDescriptor objDesc,
  727.                                     IUnknown* outer = 0) = 0;
  728.     virtual IDispatch* CreateDispatch(TObjectDescriptor objDesc,
  729.                                       IUnknown* outer = 0) = 0;
  730.     virtual void       Attach(TServedObject& obj) {}
  731.     virtual void       Detach(TServedObject& obj) {}
  732. };
  733.  
  734. class TServedObjectCreator : public TAutoCreator {
  735.   public:
  736.     TServedObjectCreator(TAppDescriptor& appDesc);
  737.     TUnknown*  CreateObject(TObjectDescriptor objDesc, IUnknown* outer = 0);
  738.     IDispatch* CreateDispatch(TObjectDescriptor objDesc, IUnknown* outer = 0);
  739.     void       Attach(TServedObject& obj);
  740.     void       Detach(TServedObject& obj);
  741. //protected:
  742.     TAppDescriptor& AppDesc;
  743.     TServedObject* AppObject;
  744.   private:
  745.     int ObjCount;
  746.   friend class TServedObject;
  747. };
  748.  
  749. class _ICLASS TDispatch;
  750.  
  751. class TDispatchCreator : public TAutoCreator {
  752.   public:
  753.     TDispatchCreator() {}
  754.     TUnknown*  CreateObject(TObjectDescriptor objDesc, IUnknown* outer = 0);
  755.     IDispatch* CreateDispatch(TObjectDescriptor objDesc, IUnknown* outer = 0);
  756.   protected:
  757. };
  758.  
  759. //____________________________________________________________________________
  760. //
  761. // TServedObject - OLE object exposed for automated access of internal object
  762. //____________________________________________________________________________
  763.  
  764. DECLARE_COMBASES2(TServedCOM, IDispatch, ITypeInfo)
  765.  
  766. class _ICLASS TServedObject : public TServedCOM {
  767.     HRESULT QueryObject(const GUID far& iid, void far* far* pif);
  768.   public:
  769.     TServedObject(TObjectDescriptor& obj, TServedObjectCreator& creator,
  770.                                           IUnknown* outer=0);
  771.    ~TServedObject();
  772.     TServedObject* GetAppObject() {return Creator.AppObject;}
  773.     TServedObjectCreator& GetCreator() {return Creator;}
  774.     void* Object;          // pointer to C++ object instance, 0 if deleted
  775.     const void far* RootObject;  // pointer to object of most derived class
  776.     TAutoClass*     Class;       // class of which object is an instance
  777.     TServedObjectCreator& Creator;
  778.     operator IDispatch*();
  779.     TLangId ReqLang;             // language requested by caller
  780.     TObjectDescriptor::TDestruct Destruct;  // what to do with C++ object
  781.   private:
  782.     TServedObject*        Next;
  783.     TServedObject* far*   Prev;
  784.     // need to access local LANGID for typeinfo, either as member or as global
  785.  
  786.     // IDispatch implementation
  787.     HRESULT _IFUNC GetTypeInfoCount(unsigned int far* pctinfo);
  788.     HRESULT _IFUNC GetTypeInfo(unsigned int itinfo, LCID lcid,
  789.                                ITypeInfo* far* pptinfo);
  790.     HRESULT _IFUNC GetIDsOfNames(const IID far& riid, OLECHAR far* far* rgszNames,
  791.                                  uint cNames, LCID lcid,
  792.                                  DISPID far* rgdispid);
  793.     HRESULT _IFUNC Invoke(DISPID dispidMember, const IID far& riid, LCID lcid,
  794.                                  unsigned short wFlags,
  795.                                  DISPPARAMS far* pdispparams,
  796.                                  VARIANT far* pvarResult,
  797.                                  EXCEPINFO far* pexcepinfo,
  798.                                  unsigned int far* puArgErr);
  799.  
  800.     // ITypeInfo implementation
  801.     HRESULT _IFUNC GetTypeAttr(TYPEATTR far* far* pptypeattr);
  802.     HRESULT _IFUNC GetTypeComp(ITypeComp* far* pptcomp);
  803.     HRESULT _IFUNC GetFuncDesc(unsigned int index, FUNCDESC far* far* ppfuncdesc);
  804.     HRESULT _IFUNC GetVarDesc(unsigned int index, VARDESC far* far* ppvardesc);
  805.     HRESULT _IFUNC GetNames(MEMBERID memid, BSTR far* rgbstrNames,
  806.                             unsigned int cMaxNames,
  807.                             unsigned int far* pcNames);
  808.     HRESULT _IFUNC GetRefTypeOfImplType(unsigned int index, HREFTYPE far* phreftype);
  809.     HRESULT _IFUNC GetImplTypeFlags(unsigned int index, int far* pimpltypeflags);
  810.     HRESULT _IFUNC GetIDsOfNames(OLECHAR far* far* rgszNames,
  811.                                  unsigned int cNames,
  812.                                  MEMBERID far* rgmemid);
  813.     HRESULT _IFUNC Invoke(void far* pvInstance, MEMBERID memid,
  814.                           unsigned short wFlags,
  815.                           DISPPARAMS far *pdispparams,
  816.                           VARIANT far *pvarResult,
  817.                           EXCEPINFO far *pexcepinfo,
  818.                           unsigned int far *puArgErr);
  819.     HRESULT _IFUNC GetDocumentation(MEMBERID memid,
  820.                                     BSTR far* pbstrName,
  821.                                     BSTR far* pbstrDocString,
  822.                                     ulong far* pdwHelpContext,
  823.                                     BSTR far* pbstrHelpFile);
  824.     HRESULT _IFUNC GetDllEntry(MEMBERID memid, INVOKEKIND invkind,
  825.                                BSTR far* pbstrDllName,
  826.                                BSTR far* pbstrName,
  827.                                unsigned short far* pwOrdinal);
  828.     HRESULT _IFUNC GetRefTypeInfo(HREFTYPE hreftype,
  829.                                   ITypeInfo* far* pptinfo);
  830.     HRESULT _IFUNC AddressOfMember(MEMBERID memid, INVOKEKIND invkind,
  831.                                    void far* far* ppv);
  832.     HRESULT _IFUNC CreateInstance(IUnknown* punkOuter, const IID far& riid,
  833.                                   void far* far* ppvObj);
  834.     HRESULT _IFUNC GetMops(MEMBERID memid, BSTR far* pbstrMops);
  835.     HRESULT _IFUNC GetContainingTypeLib(ITypeLib* far* pptlib,
  836.                                         uint far* pindex);
  837.     void _IFUNC ReleaseTypeAttr(TYPEATTR far* ptypeattr);
  838.     void _IFUNC ReleaseFuncDesc(FUNCDESC far* pfuncdesc);
  839.     void _IFUNC ReleaseVarDesc(VARDESC far* pvardesc);
  840.   friend class TAppDescriptor;   // access to Next,Prev
  841. };
  842.  
  843. //____________________________________________________________________________
  844. //
  845. // TDispatch - lightweight IDispatch implementation for automation controllers
  846. //____________________________________________________________________________
  847.  
  848. DECLARE_COMBASES1(TDispatchCOM, IDispatch)
  849.  
  850. class _ICLASS TDispatch : public TDispatchCOM {
  851.   public:
  852.     TDispatch(TObjectDescriptor& obj, IUnknown* outer = 0);
  853.     void*        Object;      // pointer to C++ object instance, 0 if deleted
  854.     TAutoClass*  Class;       // class of which object is an instance
  855.     void InvalidateObject() {Object = 0;}
  856.     operator IDispatch*();
  857.   private:
  858.     // IDispatch implementation
  859.     HRESULT _IFUNC GetTypeInfoCount(unsigned int far* pctinfo);
  860.     HRESULT _IFUNC GetTypeInfo(unsigned int itinfo, LCID lcid,
  861.                                ITypeInfo* far* pptinfo);
  862.     HRESULT _IFUNC GetIDsOfNames(const IID far& riid, OLECHAR far* far* rgszNames,
  863.                                  unsigned int cNames, LCID lcid,
  864.                                  DISPID far* rgdispid);
  865.     HRESULT _IFUNC Invoke(DISPID dispidMember, const IID far& riid, LCID lcid,
  866.                                  unsigned short wFlags,
  867.                                  DISPPARAMS far* pdispparams,
  868.                                  VARIANT far* pvarResult,
  869.                                  EXCEPINFO far* pexcepinfo,
  870.                                  unsigned int far* puArgErr);
  871. };
  872.  
  873. //____________________________________________________________________________
  874. //
  875. // TAutoObject - holders for C++ object pointers for automation conversions
  876. //____________________________________________________________________________
  877.  
  878. template<class T>
  879. class TAutoObject {
  880.   public:
  881.     void operator=(IDispatch& dp);
  882.     void operator=(T* p) {P=p;}
  883.     void operator=(T& r) {P=&r;}
  884.     T& operator*() {return *P;}
  885.     operator TObjectDescriptor() {return TObjectDescriptor(P, T::ClassInfo);}
  886.     TAutoObject() : P(0) {}
  887.     TAutoObject(T* p) {P=p;}
  888.     TAutoObject(T& r) {P=&r;}
  889.     TAutoObject(IDispatch& dr);
  890.     operator T*() {return P;}
  891.     operator T&() {return *P;}
  892.   protected:
  893.     T* P;
  894.     T F();// only purpose to remove const for typeid incase T is a const class
  895. };
  896.  
  897. template<class T>
  898. TAutoObject<T>::TAutoObject(IDispatch& ifc)
  899. {
  900.   TServedObject* obj;
  901.   if (ifc.QueryInterface(IID_TServedObject, (void far* far*)&obj) != 0)
  902.     throw TXAuto(TXAuto::xForeignIDispatch);
  903.   P = (T*)DynamicCast(obj->Object, obj->Class->GetTypeInfo(), typeid(T));
  904.   if (!P)
  905.     throw TXAuto(TXAuto::xTypeMismatch);
  906. }
  907.  
  908. template<class T> void
  909. TAutoObject<T>::operator=(IDispatch& ifc)
  910. {
  911.   TServedObject* obj;
  912.   if (ifc.QueryInterface(IID_TServedObject, (void far* far*)&obj) != 0)
  913.     throw TXAuto(TXAuto::xForeignIDispatch);
  914.   P = (T*)DynamicCast(obj->Object, obj->Class->GetTypeInfo(), typeid(T));
  915.   if (!P)
  916.     throw TXAuto(TXAuto::xTypeMismatch);
  917. }
  918.  
  919. template<class T>      // for returning objects only, no IDispatch constructor
  920. class TAutoObjectDelete : public TAutoObject<T>{
  921.   public:
  922.     void operator=(T* p) {P=p;}
  923.     void operator=(T& r) {P=&r;}
  924.     TAutoObjectDelete()     : TAutoObject<T>() {}
  925.     TAutoObjectDelete(T* p) : TAutoObject<T>(p) {}
  926.     TAutoObjectDelete(T& r) : TAutoObject<T>(r) {}
  927.     operator TObjectDescriptor()
  928.         {return TObjectDescriptor(P,T::ClassInfo, TObjectDescriptor::Delete);}
  929. };
  930.  
  931. template<class T>      // for returning objects by value
  932. class TAutoObjectByVal : public TAutoObjectDelete<T> {
  933.   public:
  934.     void operator=(T o) {P=new T(o);}
  935.     TAutoObjectByVal() : TAutoObjectDelete<T>() {}
  936.     TAutoObjectByVal(T o) : TAutoObjectDelete<T>(new T(o)) {}
  937. };
  938.  
  939. //____________________________________________________________________________
  940. //
  941. // TAutoIterator - automation collection iterator
  942. //____________________________________________________________________________
  943.  
  944.  
  945. class TAutoIterator : public IEnumVARIANT {
  946.   public:
  947.     // IEnumVARIANT implementation
  948.     HRESULT       _IFUNC QueryInterface(const GUID far& iid, void far*far* pif);
  949.     unsigned long _IFUNC AddRef();
  950.     unsigned long _IFUNC Release();
  951.     HRESULT _IFUNC Next(unsigned long count, VARIANT far* retvals,
  952.                         unsigned long far* retcount);
  953.     HRESULT _IFUNC Skip(unsigned long count);
  954.     HRESULT _IFUNC Reset();
  955.     HRESULT _IFUNC Clone(IEnumVARIANT* far* retiter);
  956.  
  957.     // specific implementation required by derived classes
  958.     virtual void           Init()=0;   // reset to first item
  959.     virtual bool           Test()=0;   // test if item exists
  960.     virtual void           Step()=0;   // advance to next item
  961.     virtual void           Return(TAutoVal& v)=0;// convert item to variant
  962.     virtual TAutoIterator* Copy()=0;   // return copy of iterator
  963.  
  964.     // inline data member accessor functions
  965.     TAutoSymbol* GetSymbol();
  966.     void SetSymbol(TAutoSymbol* sym);
  967.     operator IUnknown*();     // essentially a quick QueryInterface
  968.  
  969.     virtual ~TAutoIterator();
  970.     TAutoClass* Class;
  971.   protected:
  972.     TAutoSymbol* Symbol;      // symbol entry generating this command
  973.     TAutoCreator& Creator;    // object to create returned automation objects
  974.     IUnknown* Owner;          // Release() must be called on destruction
  975.     unsigned RefCnt;
  976.     TLangId Lang;
  977.     TAutoIterator(TAutoCreator& creator, IUnknown* owner, TLangId lang); // called from derived
  978.     TAutoIterator(TAutoIterator& copy);  // copy constructor for base class
  979.   };
  980.  
  981. //____________________________________________________________________________
  982. //
  983. // TAutoProxy - client C access proxy, base class
  984. //____________________________________________________________________________
  985.  
  986. enum AutoCallFlag {
  987.   acMethod         = 0x0001,  // method call, same as OLE2
  988.   acPropGet        = 0x0002,  // returns property value, same as OLE2
  989.   acPropSet        = 0x0004,  // set property value, same as OLE2
  990.   acVoidRet        = 0x8000,  // pass NULL for return variant, not OLE2 flag
  991. };
  992.  
  993. class TAutoProxyArgs {
  994.   public:
  995.     TAutoProxyArgs(int cnt) : Count(cnt) {}
  996.    ~TAutoProxyArgs();
  997.     TAutoVal& operator[](int index);
  998.     operator TAutoVal&()    {return *(TAutoVal*)(this+1);}
  999.     operator VARIANT far*() {return (VARIANT far*)(this+1);}
  1000.     operator unsigned int() {return Count;}
  1001.   private:
  1002.     int Count;
  1003. };
  1004.  
  1005. template <int N>
  1006. struct TAutoArgs : public TAutoProxyArgs {
  1007.   TAutoVal Args[N+1];
  1008.   TAutoArgs() : TAutoProxyArgs(N) {}
  1009. };
  1010.  
  1011. class TAutoProxy {
  1012.   public:
  1013.    ~TAutoProxy();
  1014.     void Bind(IUnknown* obj);
  1015.     void Bind(IUnknown& obj);
  1016.     void Bind(const GUID& guid);
  1017.     void Bind(const char far* progid);
  1018.     void Bind(TAutoVal& val);
  1019.     void Bind(IDispatch* obj);
  1020.     void Bind(IDispatch& obj);
  1021.     void Unbind();
  1022.     void MustBeBound();
  1023.     bool IsBound()  {return ToBool(That != 0);}
  1024.     void SetLang(TLangId lang) {Lang = lang;}
  1025.     operator IDispatch*();
  1026.     operator IDispatch&();
  1027.     long      Lookup(const long id) {return id;}
  1028.     long      Lookup(const char far* name);
  1029.     void      Lookup(const char far* names, long* ids, unsigned count);
  1030.   protected:
  1031.     TAutoProxy(TLangId lang) : That(0), Lang(lang) {}
  1032.     TAutoVal& Invoke(uint16 attr, TAutoProxyArgs& args, long* ids, unsigned named=0);
  1033.     IDispatch* That;
  1034.     TLangId Lang;
  1035. };
  1036.  
  1037. struct TAutoDispId {
  1038.   TAutoDispId(TAutoProxy* prx, const char* name) : Id(prx->Lookup(name)) {}
  1039.   TAutoDispId(TAutoProxy*, long id) : Id(id) {}
  1040.   long Id;
  1041.   operator long*()  {return &Id;}
  1042.   operator unsigned() {return 0;}
  1043. };
  1044.  
  1045. template <int N> struct TAutoDispIds {
  1046.   TAutoDispIds(TAutoProxy* prx, const char* names) {prx->Lookup(names, Ids);}
  1047.   long Ids[N+1];
  1048.   operator long*()  {return Ids;}
  1049.   operator unsigned() {return N;}
  1050. };
  1051.  
  1052. class TAutoEnumeratorBase {
  1053.   public:
  1054.     void Bind(TAutoVal& val);
  1055.     void Unbind()   { if (Iterator) Iterator->Release(); Iterator=0; Clear();}
  1056.     bool Step();
  1057.     void Clear()      { Current.Clear(); }
  1058.     bool IsValid()    { return Current.GetDataType() != atVoid; }
  1059.     void Object(TAutoProxy& prx) { prx.Bind(Current); }
  1060.     void operator =(const TAutoEnumeratorBase& copy);
  1061.    ~TAutoEnumeratorBase() { Unbind(); }
  1062.   protected:
  1063.     TAutoEnumeratorBase() : Iterator(0) {Current = TAutoVoid();}
  1064.     TAutoEnumeratorBase(const TAutoEnumeratorBase& copy);
  1065.     IEnumVARIANT* Iterator;
  1066.     TAutoVal Current;
  1067. };
  1068.  
  1069. template <class T>
  1070. class TAutoEnumerator : public TAutoEnumeratorBase {
  1071.   public:
  1072.     TAutoEnumerator() : TAutoEnumeratorBase() {}
  1073.     TAutoEnumerator(const TAutoEnumerator<T>& cpy) : TAutoEnumeratorBase(cpy) {}
  1074.     void Value(T& v);
  1075.     operator T();
  1076. };
  1077.  
  1078. //____________________________________________________________________________
  1079. //
  1080. // Inline implementations for automation controller
  1081. //____________________________________________________________________________
  1082.  
  1083. inline TAutoVal& TAutoProxyArgs::operator[](int index)
  1084. {
  1085.   return *((TAutoVal*)(this+1)+(index ? Count+1-index : 0));
  1086. }
  1087.  
  1088. inline TAutoProxy::operator IDispatch&()  // this function not used internally
  1089. {
  1090.   if (!That)   // test only needed if inline to prevent function call overhead
  1091.     MustBeBound();
  1092.   return *That;
  1093. }
  1094.  
  1095. inline TAutoProxy::operator IDispatch*()
  1096. {
  1097.   if (That)
  1098.     That->AddRef();
  1099.   return That;
  1100. }
  1101.  
  1102. inline void TAutoProxy::Unbind()
  1103. {
  1104.   if (That)
  1105.     That->Release();
  1106.   That = 0;
  1107. }
  1108.  
  1109. inline TAutoProxy::~TAutoProxy()
  1110. {
  1111.   Unbind();
  1112. }
  1113.  
  1114. inline void TAutoEnumerator<short>::Value(short& v) { v = Current; }
  1115. inline void TAutoEnumerator<long>::Value(long& v)   { v = Current; }
  1116. inline void TAutoEnumerator<bool>::Value(bool& v)   { v = Current; }
  1117. inline void TAutoEnumerator<TAutoString>::Value(TAutoString& v)
  1118.                                                     { v = Current; }
  1119.  
  1120. inline TAutoEnumerator<short>::operator short() { return (short)Current; }
  1121. inline TAutoEnumerator<long>::operator long()   { return (long)Current; }
  1122. inline TAutoEnumerator<bool>::operator bool()   { return (bool)Current; }
  1123. inline TAutoEnumerator<TAutoString>::operator TAutoString()
  1124.                                                 { return (TAutoString)Current; }
  1125. //____________________________________________________________________________
  1126. //
  1127. // Inline implementations for automation server - part 1
  1128. //____________________________________________________________________________
  1129.  
  1130. // TAutoClass inlines
  1131.  
  1132. inline TAutoSymbol* TAutoClass::GetTable()       {return Table;}
  1133. inline TAutoSymbol* TAutoClass::GetClassSymbol() {return ClassSymbol;}
  1134. inline TAutoCommandBuildDtr TAutoClass::GetDestructor() {return ClassSymbol->BuildDtr;}
  1135. inline const typeinfo&  TAutoClass::GetTypeInfo()    {return TypeInfo;}
  1136. inline const char* TAutoClass::GetName(TLangId id) {return ClassSymbol->Name.Translate(id);}
  1137. inline const char* TAutoClass::GetDoc (TLangId id) {return ClassSymbol->Doc.Translate(id);}
  1138. inline unsigned long TAutoClass::GetHelpId() {return ClassSymbol->HelpId;}
  1139. inline unsigned short TAutoClass::GetTypeFlags()
  1140.                             {return ClassSymbol->TypeFlags & tfAutoClassMask;}
  1141. inline int TAutoClass::GetImplTypeFlags() {return ClassSymbol->TypeFlags>>12;}
  1142. inline unsigned short TAutoClass::GetCoClassFlags()
  1143.                             {return ClassSymbol->TypeFlags & tfCoClassXfer;}
  1144. inline TAggregator TAutoClass::GetAggregator() {return Aggregator;}
  1145. inline IUnknown& TAutoClass::Aggregate(ObjectPtr obj, TUnknown& inner)
  1146.         {return obj && Aggregator ? Aggregator(obj, inner) : (IUnknown&)inner;}
  1147. //____________________________________________________________________________
  1148.  
  1149. // TAutoSymbol inlines
  1150.  
  1151. inline void TAutoSymbol::SetFlag(uint16 mask) {Attr |= mask;}
  1152. inline void TAutoSymbol::ClearFlag(uint16 mask) {Attr &= uint16(~mask);}
  1153. inline bool TAutoSymbol::TestFlag(uint16 mask) {return (Attr&mask)? true:false;}
  1154. inline uint16 TAutoSymbol::GetFlags() {return (uint16)Attr;}
  1155. inline bool TAutoSymbol::IsEnum() {return (Type->GetType() & atEnum)? true:false;}
  1156. inline bool TAutoSymbol::IsByRef() {return (Type->GetType() & atByRef)? true:false;}
  1157. inline bool TAutoSymbol::IsArray() {return (Type->GetType() & atSafeArray)? true:false;}
  1158. inline bool TAutoSymbol::IsIterator() {return ToBool((Attr&asIterator)==asIterator);}
  1159. inline bool TAutoSymbol::IsTerminator() {return ToBool((Attr & asNotTerminator)== 0);}
  1160. inline uint16 TAutoSymbol::GetDataType() {return uint16(Type->GetType() & atTypeMask);}
  1161. inline TAutoClass* TAutoSymbol::GetClass(){return (Type->GetType()&atAutoClass)?
  1162.                                                       (TAutoClass*)Type : 0; }
  1163. inline TAutoEnum* TAutoSymbol::GetEnum() {return (Type->GetType()&atEnum) ?
  1164.                                                       (TAutoEnum*)Type : 0; }
  1165. inline TAutoCommandBuild TAutoSymbol::InitTypeConvert(TAutoSymTypeConvert f)
  1166.                                          { return (TAutoCommandBuild)f;}
  1167. inline TAutoCommandBuild TAutoSymbol::InitAutoIterator(TAutoIteratorBuild f)
  1168.                                          { return (TAutoCommandBuild)f;}
  1169. inline TAutoCommandBuild TAutoSymbol::InitAutoDestructor(TAutoCommandBuildDtr f)
  1170.                                          { return (TAutoCommandBuild)f;}
  1171. //____________________________________________________________________________
  1172.  
  1173. // TAutoVal inlines
  1174.  
  1175. inline TAutoVal::operator unsigned long(){return (unsigned long)operator long();}
  1176. #if (MAXINT==MAXSHORT)
  1177. inline TAutoVal::operator int()          {return operator short();}
  1178. inline TAutoVal::operator unsigned int() {return operator unsigned short();}
  1179. inline TAutoVal::operator int far*()     {return (int far*)operator short far*();}
  1180. #else
  1181. inline TAutoVal::operator int()          {return operator long(); }
  1182. inline TAutoVal::operator unsigned int() {return (unsigned long)(long)*this;}
  1183. inline TAutoVal::operator int far*()     {return (int far*)operator long far*();}
  1184. #endif
  1185.  
  1186. inline TAutoVal::operator TAutoBool()  {return TAutoBool(operator TBool());}
  1187. inline TAutoVal::operator TAutoBoolRef(){return TAutoBoolRef(operator TBool far*());}
  1188. inline TAutoVal::operator signed char(){return operator unsigned char();}
  1189. inline TAutoVal::operator char()       {return operator unsigned char();}
  1190. inline TAutoVal::operator char far*()  {return (char far*)operator unsigned char far*();}
  1191. inline TAutoVal::operator signed char far*(){return (signed char far*)operator unsigned char far*();}
  1192.  
  1193. inline void TAutoVal::operator =(IDispatch* ifc) {vt=atObject; pdispVal=ifc;}
  1194. inline void TAutoVal::operator =(IUnknown* ifc)  {vt=atUnknown; punkVal=ifc;}
  1195. inline void TAutoVal::operator =(unsigned char v){vt=atByte;   bVal  = v;}
  1196. inline void TAutoVal::operator =(signed char v)  {vt=atByte;   bVal  = v;}
  1197. inline void TAutoVal::operator =(char v)         {vt=atByte;   bVal  = v;}
  1198. inline void TAutoVal::operator =(short  v)       {vt=atShort;  iVal  = v;}
  1199. inline void TAutoVal::operator =(long   v)       {vt=atLong;   lVal  = v;}
  1200. inline void TAutoVal::operator =(float  v)       {vt=atFloat;  fltVal= v;}
  1201. inline void TAutoVal::operator =(double v)       {vt=atDouble; dblVal= v;}
  1202. inline void TAutoVal::operator =(TBool  v)   {vt=atBool; boolVal = short(v ? -1 : 0);}
  1203. inline void TAutoVal::operator =(TAutoBool v){vt=atBool; boolVal = short((bool)v ? -1 : 0);}
  1204. inline void TAutoVal::operator =(TAutoDate v)    {vt=atDatetime; date = v;}
  1205. inline void TAutoVal::operator =(TAutoCurrency v){vt=atCurrency; cyVal = v;}
  1206. inline void TAutoVal::operator =(TAutoVoid)      {vt=atVoid;}
  1207. inline void TAutoVal::operator =(unsigned char far* p){vt=atByte+atByRef; pbVal=p;}
  1208. inline void TAutoVal::operator =(signed char far* p){vt=atByte+atByRef; pbVal=(unsigned char far*) p;}
  1209. inline void TAutoVal::operator =(char far* p)       {vt=atByte+atByRef; pbVal=(unsigned char far*) p;}
  1210. inline void TAutoVal::operator =(short far* p) {vt=atShort+atByRef; piVal=p;}
  1211. inline void TAutoVal::operator =(long far* p)  {vt=atLong+atByRef;  plVal=p;}
  1212. inline void TAutoVal::operator =(TBool far* p) {vt=atBool+atByRef;  pbool=(VARIANT_BOOL far*)p;}
  1213. inline void TAutoVal::operator =(TAutoBoolRef p){vt=atBool+atByRef; pbool=(VARIANT_BOOL far*)(bool far*)p;}
  1214. inline void TAutoVal::operator =(float far* p) {vt=atFloat+atByRef; pfltVal=p;}
  1215. inline void TAutoVal::operator =(double far* p){vt=atDouble+atByRef;pdblVal=p;}
  1216. inline void TAutoVal::operator =(TAutoDate far* p){vt=atDatetime+atByRef;pdate=(double far*)p;}
  1217. inline void TAutoVal::operator =(TAutoCurrency far* p){vt=atCurrency+atByRef;pcyVal=p;}
  1218.  
  1219. inline void TAutoVal::operator =(unsigned short v){vt=atLong; lVal = (long)v;}
  1220. inline void TAutoVal::operator =(unsigned short far* p)
  1221.                                   {vt=atShort+atByRef; piVal = (short far*)p;}
  1222. inline void TAutoVal::operator =(unsigned long v) {vt=atLong; lVal = (long)v;}
  1223. inline void TAutoVal::operator =(unsigned long far* p)
  1224.                                     {vt=atLong+atByRef; plVal = (long far*)p;}
  1225. #if (MAXINT==MAXSHORT)
  1226. inline void TAutoVal::operator =(int v) {vt=atShort; iVal=v;}
  1227. inline void TAutoVal::operator =(int far* p) {vt=atShort+atByRef; piVal=(short far*)p;}
  1228. inline void TAutoVal::operator =(unsigned int v) {operator =((unsigned short)v);}
  1229. inline void TAutoVal::operator =(unsigned int far* p) {operator =((unsigned short far*)p);}
  1230. #else
  1231. inline void TAutoVal::operator =(int v) {vt=atLong; lVal=v;}
  1232. inline void TAutoVal::operator =(int far* p) {vt=atLong+atByRef; plVal = (long far*)p;}
  1233. inline void TAutoVal::operator =(unsigned int v) {operator =((unsigned long)v);}
  1234. inline void TAutoVal::operator =(unsigned int far* p) {operator =((unsigned long far*)p);}
  1235. #endif
  1236.  
  1237. inline void TAutoVal::operator =(TObjectDescriptor od)
  1238.   {vt=atObjectDesc; ObjDesc.Object=od.Object; ObjDesc.Class=od.Class;
  1239.    if (od.Destruct == TObjectDescriptor::Delete) vt |= atByRef;}
  1240.  
  1241. inline int TAutoVal::GetDataType() {return vt;}
  1242.  
  1243. inline void TAutoVal::Clear()
  1244. {
  1245.   if ((vt & ~atByRef) == atLoanedBSTR) {
  1246.     s.Holder->ReleaseBstr((vt & atByRef) ? *pbstrVal : bstrVal);
  1247.     vt = uint16(atString | (vt & atByRef));
  1248.   }
  1249.   ::VariantClear((VARIANT far*)this);
  1250. }
  1251.  
  1252. inline void TAutoVal::Restore()
  1253. {
  1254.   if ((vt & ~atByRef) == atLoanedBSTR) {
  1255.     s.Holder->RevokeBstr((vt & atByRef) ? *pbstrVal : bstrVal);
  1256.     vt = uint16(atString | (vt & atByRef));
  1257.   } else if (vt == uint16(atBool | atByRef) && *pbool != 0) {
  1258.     *pbool = -1;
  1259.   }
  1260.   // need to check if atObjectDesc? should never happen as it is temporary
  1261. }
  1262.  
  1263. inline void TAutoVal::Copy(const TAutoVal& copy)
  1264. {
  1265.   vt = copy.vt;
  1266.   p  = copy.p;
  1267.   if (vt == atUnknown || vt == atObject)
  1268.     punkVal->AddRef();
  1269.   if (vt == atString)
  1270.     bstrVal = ::SysAllocString(bstrVal);
  1271. }
  1272.  
  1273. inline bool TAutoVal::IsRef() {return ToBool(vt & atByRef);}
  1274.  
  1275. inline TAutoVal far* TAutoVal::DereferenceVariant()
  1276.                {return vt==atVariant+atByRef ? (TAutoVal far*)pvarVal : this;}
  1277.  
  1278. inline TString TAutoVal::StrVal() {return vt==atString ? bstrVal : 0;}
  1279.  
  1280. inline bool TAutoVal::GetObjDesc(TObjectDescriptor& od)
  1281. {
  1282.   if ((char)vt != atObjectDesc)
  1283.     return false;
  1284.   od.Object = ObjDesc.Object;
  1285.   od.Class = ObjDesc.Class;
  1286.   od.Destruct = IsRef() ? TObjectDescriptor::Delete : TObjectDescriptor::Quiet;
  1287.   return true;
  1288. }
  1289.  
  1290. inline SAFEARRAY far* TAutoVal::GetArray()
  1291. {
  1292.   if (vt == atSafeArray)
  1293.     return parray;
  1294.   if (vt == (atSafeArray|atByRef))
  1295.     return *pparray;
  1296.   return 0;
  1297. }
  1298.  
  1299. inline void far* TAutoVal::SetByRef(AutoDataType datatype)
  1300. {
  1301.   if (vt == atVariant)
  1302.     return this;
  1303.   vt = uint16(datatype);
  1304.   return &byref;
  1305. }
  1306.  
  1307. //____________________________________________________________________________
  1308.  
  1309. // TServedObject inlines
  1310.  
  1311. inline TServedObject::operator IDispatch*()
  1312. {
  1313.   AddRef();
  1314.   return (IDispatch*)this;  // essentially a quick QueryInterface on the obj
  1315. }
  1316.  
  1317. // TDispatch inlines
  1318.  
  1319. inline TDispatch::operator IDispatch*()
  1320. {
  1321.   AddRef();
  1322.   return (IDispatch*)this;  // essentially a quick QueryInterface on the obj
  1323. }
  1324.  
  1325. //____________________________________________________________________________
  1326.  
  1327. // TAutoCommand inlines
  1328.  
  1329. inline TAutoCommand::TAutoCommand(int attr) : Attr(attr), Symbol(0) {}
  1330. inline void TAutoCommand::SetFlag(int mask) {Attr |= mask;}
  1331. inline void TAutoCommand::ClearFlag(int mask) {Attr&=(~mask);}
  1332. inline bool TAutoCommand::TestFlag(int mask) {return ToBool((Attr&mask)==mask);}
  1333. inline bool TAutoCommand::IsPropSet() {return TestFlag(asSet);}
  1334. inline TAutoSymbol* TAutoCommand::GetSymbol() {return Symbol;}
  1335. inline void TAutoCommand::SetSymbol(TAutoSymbol* sym) {Symbol = sym;}
  1336. inline const char* TAutoCommand::LookupError(long errCode)
  1337.     {return TAutoCommand_ErrorLookup ? TAutoCommand_ErrorLookup(errCode) : 0;}
  1338. //____________________________________________________________________________
  1339.  
  1340. // TAutoEnum inlines and template function definitions
  1341.  
  1342. inline TAutoEnum::TAutoEnum(int count, int type)
  1343.                         : Count(count) { Type = short(type + atEnum); }
  1344.  
  1345. template <class T> inline
  1346. TAutoEnumT<T>::TAutoEnumT(TAutoEnumVal<T>* table, int symcount, int type)
  1347. : TAutoEnum(symcount, type), Table(table) {}
  1348.  
  1349. // incoming enumeration string localized lookup
  1350. //
  1351. template <class T> bool
  1352. TAutoEnumT<T>::Convert(TAutoVal& txtVal, TAutoVal& numVal)
  1353. {
  1354.   const char far* str = txtVal.StrVal();  // 0 if not string type
  1355.   if (str) {
  1356.     TLangId langId = txtVal.GetLanguage();
  1357.     for (int i = 0; i < Count; i++) {
  1358.       if (Table[i].Name.Compare(str, langId) == 0) {
  1359.         numVal = Table[i].Val;
  1360.         return true;
  1361.       }
  1362.     }
  1363.   }
  1364.   return false;
  1365. }
  1366.  
  1367. // outgoing enumeration translation to localized string
  1368. //
  1369. template <class T> bool
  1370. TAutoEnumT<T>::Convert(TAutoVal& numVal, TLangId langId)
  1371. {
  1372.   T val;
  1373.   val = numVal;  // perhaps we should put a try/catch here!!
  1374.   for (int i = 0; i < Count; i++) {
  1375.     if (Table[i].Val == val) {
  1376.       numVal = Table[i].Name.Translate(langId);
  1377.       numVal.SetLocale(langId);
  1378.       return true;
  1379.     }
  1380.   }
  1381.   return false;
  1382. }
  1383.  
  1384. // special case for outgoing string enumerations
  1385. //
  1386. #pragma warn -inl
  1387. inline bool
  1388. TAutoEnumT<const char*>::Convert(TAutoVal& numVal, TLangId langId)
  1389. {
  1390.   const char far* str = numVal.StrVal();  // 0 if not string type
  1391.   if (str)
  1392.     for (int i = 0; i < Count; i++) {
  1393.       if (lstrcmp(Table[i].Val, str) == 0) {
  1394.         numVal = Table[i].Name.Translate(langId);
  1395.         numVal.SetLocale(langId);
  1396.         return true;
  1397.       }
  1398.     }
  1399.   return false;
  1400. }
  1401. #pragma warn .inl
  1402.  
  1403. //____________________________________________________________________________
  1404.  
  1405. // TAutoIterator inlines
  1406.  
  1407. inline TAutoIterator::operator IUnknown*() {RefCnt++; return this;}
  1408. inline TAutoSymbol* TAutoIterator::GetSymbol() {return Symbol;}
  1409. inline void TAutoIterator::SetSymbol(TAutoSymbol* sym) {Symbol = sym;}
  1410.  
  1411. //____________________________________________________________________________
  1412. //
  1413. // Inline implementations for automation server - part 2
  1414. //   These are inline only for the purpose of allowing _AUTOCLASS
  1415. //   to be specified at compile time without rebuilding OCF library
  1416. //   This applies to classes: TAutoBase, TAutoCommand, TAutoDetach
  1417. //____________________________________________________________________________
  1418.  
  1419. inline TAutoBase::~TAutoBase()
  1420. {
  1421.   ::SendObituary(this, typeid(TAutoBase));
  1422. }
  1423.  
  1424. inline void TAutoDetach::Notify(int offset, const typeinfo& typeInfo)
  1425. {
  1426.   ::SendObituary((char*)this-offset, typeInfo);
  1427. }
  1428. //____________________________________________________________________________
  1429.  
  1430. // TAutoCommand implementation specified inline to avoid _AUTOCLASS link errors
  1431.  
  1432. inline void TAutoCommand::Fail(TXAuto::TError err) { throw TXAuto(err); }
  1433.  
  1434. inline bool TAutoCommand::Validate() { return true; }
  1435.  
  1436. inline TAutoCommand& TAutoCommand::Invoke()
  1437. {
  1438.   if (!TAutoCommand_InvokeHook || TAutoCommand_InvokeHook(*this))
  1439.     Execute();
  1440.   return *this;
  1441. }
  1442.  
  1443. inline void TAutoCommand::Execute()
  1444. {
  1445. }
  1446.  
  1447. inline long TAutoCommand::Report()
  1448. {
  1449.   return 0;
  1450. }
  1451.  
  1452. inline void TAutoCommand::Return(TAutoVal& v)
  1453. {
  1454.   v = TAutoVoid();
  1455. }
  1456.  
  1457. inline void TAutoCommand::Transfer(TAutoTransfer& x)
  1458. {
  1459. }
  1460.  
  1461. inline TAutoCommand* TAutoCommand::Undo() {return 0;}
  1462.  
  1463. inline int TAutoCommand::Record(TAutoStack&) {return 0;}
  1464.  
  1465. inline TAutoCommand::TErrorMsgHook
  1466. TAutoCommand::SetErrorMsgHook(TAutoCommand::TErrorMsgHook callback){
  1467.   TErrorMsgHook hook = TAutoCommand_ErrorLookup;
  1468.   TAutoCommand_ErrorLookup = callback;
  1469.   return hook;
  1470. }
  1471.  
  1472. inline TAutoCommand::TCommandHook
  1473. TAutoCommand::SetCommandHook(TAutoCommand::TCommandHook callback){
  1474.   TCommandHook hook = TAutoCommand_InvokeHook;
  1475.   TAutoCommand_InvokeHook = callback;
  1476.   return hook;
  1477. }
  1478.  
  1479. #endif  // OCF_AUTODEFS_H
  1480.  
  1481.  
  1482.