OLE.h

Go to the documentation of this file.
00001 /*  
00002  *      OLEAutomation.h - OLE Automation services for MAXScript
00003  *
00004  *          Copyright (c) John Wainwright 1996
00005  *
00006  */
00007 
00008 #pragma once
00009 
00010 #include "..\foundation\arrays.h"
00011 #include "..\foundation\functions.h"
00012 #include "OLE.classids.h"
00013 
00014 /* error scodes */
00015 
00016 #define MS_E_EXCEPTION                  MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, 0x0200)  
00017 #define MS_E_ILLEGAL_RETURN_VALUE       MS_E_EXCEPTION + 0x001  
00018 
00019 /* ------- the MAXScript OLE object class factory ---------- */
00020 
00021 class MSClassFactory : public IClassFactory
00022 {
00023 public:
00024     static IClassFactory* Create();
00025 
00026     /* IUnknown methods */
00027     STDMETHOD(QueryInterface)(REFIID iid, void** ppv);
00028     STDMETHOD_(unsigned long, AddRef)(void);
00029     STDMETHOD_(unsigned long, Release)(void);
00030 
00031     /* IClassFactory methods */
00032     STDMETHOD(CreateInstance)(IUnknown* pUnkOuter, REFIID iid, void** ppv);
00033     STDMETHOD(LockServer)(BOOL fLock);
00034 
00035 private:
00036     MSClassFactory();
00037 
00038     unsigned long m_refs;
00039 };
00040 
00041 /* ---------- the MAXScript OLE object class -------------- */
00042 
00043 class MSOLEObject : public IDispatch
00044 {
00045 public:
00046     static MSOLEObject* Create();
00047 
00048     /* IUnknown methods */
00049     STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj);
00050     STDMETHOD_(unsigned long, AddRef)(void);
00051     STDMETHOD_(unsigned long, Release)(void);
00052 
00053     /* IDispatch methods */
00054     STDMETHOD(GetTypeInfoCount)(unsigned int* pcTypeInfo);
00055     STDMETHOD(GetTypeInfo)(unsigned int iTypeInfo, LCID lcid, ITypeInfo** ppTypeInfo);
00056     STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR** rgszNames, unsigned int cNames, LCID lcid, DISPID* rgdispid);
00057     STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid, unsigned short wFlags,
00058                       DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, unsigned int* puArgErr);
00059 
00060     /* MSOLEObject stuff */
00061 
00062     unsigned long m_refs;
00063     static Array* exposed_fns;      // array of exposed MAXScript functions, DISPID is 1-based index in array
00064 
00065     MSOLEObject();
00066 
00067     static void install_fns(Array* fns);
00068 };
00069 
00070 /* ---------------- client-side classes -------------------- */
00071 
00072 visible_class (OLEObject)
00073 
00074 class OLEObject : public Value
00075 {
00076 public:
00077     Value*      progID;     // user-supplied progID string
00078     CLSID       clsid;      // CLSID of ActiveX object.
00079     LPDISPATCH  pdisp;      // IDispatch of ActiveX object.
00080 
00081                 OLEObject(Value* progID, CLSID cslid, LPDISPATCH pdisp);
00082                 OLEObject(Value* progID, LPDISPATCH pdisp);
00083                ~OLEObject();
00084     #define     is_OLEObject(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(OLEObject))
00085 
00086                 classof_methods (OLEObject, Value);
00087     void        collect() { delete this; }
00088     void        gc_trace();
00089     ScripterExport void     sprin1(CharStream* s);
00090 
00091     Value*      get_property(Value** arg_list, int count);
00092     Value*      set_property(Value** arg_list, int count);
00093     Value*      get_fn_property(Value* prop);
00094 };
00095 
00096 visible_class (OLEMethod)
00097 
00098 class OLEMethod : public Function
00099 {
00100 public:
00101     OLEObject*  ole_obj;    // my OLE object
00102     DISPID      dispid;     // method dispatch ID
00103 
00104                 OLEMethod() { }
00105                 OLEMethod(MCHAR* name, OLEObject* ole_obj, DISPID mth_id);
00106     #define     is_OLEMethod(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(OLEMethod))
00107 
00108                 classof_methods (OLEMethod, Function);
00109     void        collect() { delete this; }
00110     void        gc_trace();
00111 
00112     Value*      apply(Value** arglist, int count, CallContext* cc=NULL);
00113 };
00114 
00115 /* ---------------- SAFEARRAY wrapper class -------------------- */
00116 applyable_class_debug_ok (SafeArrayWrapper)
00117 
00118 // MXS Value helper class for converting between MXS Arrays and OLE SAFEARRAYs.
00119 class SafeArrayWrapper : public Value
00120 {
00121     friend SafeArrayWrapperClass;
00122 public:
00123     Value*  dataArray;
00124     Value*  lBoundsArray;
00125     int     numDims;
00126 
00127 // Creates SafeArrayWrapper with empty data and lBounds arrays.
00128     ScripterExport SafeArrayWrapper();
00129 // Creates SafeArrayWrapper with data array and empty lBounds array.
00130 // \pre dataArray must be non-null
00131 // \param[in] dataArray The data array
00132 // \param[in] nDims The dimensions of the data array
00133     ScripterExport SafeArrayWrapper(Array* dataArray, int nDims);
00134 // Creates SafeArrayWrapper with data and lBounds array.
00135 // \pre dataArray must be non-null
00136 // \pre lboundsArray must be non-null
00137 // \param[in] dataArray The data array
00138 // \param[in] lBoundsArray The lBounds array
00139 // \param[in] nDims The dimensions of the data and lBounds array
00140     ScripterExport SafeArrayWrapper(Array* dataArray, Array* lBoundsArray, int nDims);
00141 // Creates SafeArrayWrapper from SAFEARRAY.
00142 // \pre psa must be non-null
00143 // \param[in] psa The SAFEARRAY to build the data and lBounds array from
00144 // \param[in] progID user-supplied progID string of the creating object 
00145     ScripterExport SafeArrayWrapper(SAFEARRAY *psa, Value* progID);
00146 // Creates OLE SAFEARRAY based on data and lBounds array.
00147 // if dataArray is 'undefined', throws exception
00148 // if lBoundsArray is 'undefined', lower bounds of 0 used
00149 // if dataArray is not "square", throws exception
00150 // \return the SAFEARRAY
00151     ScripterExport SAFEARRAY* to_SAFEARRAY();
00152 
00153 // Calculates number of dimensions of input Array.
00154 // \pre testArray must be non-null
00155 // \param[in] testArray Array to calculate the dimensions of
00156 // \return Number of dimensions
00157     ScripterExport static int       GetDataArrayDimensions(Array* testArray);
00158 // Calculates the array size for each dimension.
00159 // Verifies the arrays size in each dimension is consistent across array - throws runtime error if not.
00160 // \pre testArray can be null
00161 // \pre pCount must be non-null
00162 // \post pCount is filled with array size for each dimension
00163 // \param[in] testArray Array to calculate the dimensions of
00164 // \param[in] nDims The dimensions of the Array
00165 // \param[in,out] pCount pointer to nDims size int array. Method fills array with array size for each dimension
00166     ScripterExport static void      CheckDataArray(Array* testArray, int nDims, int* pCount = NULL);
00167 
00168 #define     is_SafeArrayWrapper(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(SafeArrayWrapper))
00169 
00170     classof_methods (SafeArrayWrapper, Value);
00171     void        collect() { delete this; }
00172     void        gc_trace();
00173     ScripterExport void sprin1(CharStream* s);
00174 
00175     /* operations */
00176 
00177 #include "..\macros\define_implementations.h"
00178     use_generic( copy,      "copy");
00179 
00180     Value*      get_property(Value** arg_list, int count);
00181     Value*      set_property(Value** arg_list, int count);
00182 
00183 };
00184 
00185 
00186 BOOL init_MAXScript_OLE();
00187 void uninit_OLE();
00188 
00189 #define UNUSED(X) (X)
00190