GME
13
|
00001 // ComponentProxy.cpp : Implementation of CComponentProxy 00002 #include "stdafx.h" 00003 #include "MgaUtil.h" 00004 #include "ComponentProxy.h" 00005 00006 #define CHECK_INIT { if (m_dispatch == NULL) return E_MGAUTIL_COMPONENTPROXY_NOTINITIALIZED; } 00007 00009 // CComponentProxy 00010 00011 // IMgaComponentProxy implementation 00012 STDMETHODIMP CComponentProxy::put_DispatchComponent(/*[in]*/ IDispatch *component) 00013 { 00014 m_dispatch = component; 00015 DISPID dispid; 00016 return m_dispatch.GetIDOfName(OLESTR("InvokeEx"), &dispid); // Just a simple check on the dispatch interface 00017 // return S_OK; 00018 } 00019 00020 // IMgaComponent implementation 00021 STDMETHODIMP CComponentProxy::Invoke(/*[in]*/ IMgaProject *project, /*[in]*/ IMgaFCOs *selectedobjs, /*[in]*/ long param) 00022 { 00023 CHECK_INIT; 00024 CComVariant varArgs[3]; 00025 varArgs[2] = project; 00026 varArgs[1] = selectedobjs; 00027 varArgs[0] = param; 00028 return m_dispatch.InvokeN(OLESTR("Invoke"), &varArgs[0], 3, NULL); 00029 } 00030 00031 STDMETHODIMP CComponentProxy::Initialize(IMgaProject *p) 00032 { 00033 CHECK_INIT; 00034 CComVariant vp(p); 00035 return m_dispatch.Invoke1(OLESTR("Initialize"), &vp, NULL); 00036 } 00037 00038 STDMETHODIMP CComponentProxy::Enable(VARIANT_BOOL newVal) 00039 { 00040 CHECK_INIT; 00041 CComVariant vnewVal(newVal); 00042 return m_dispatch.Invoke1(OLESTR("Enable"), &vnewVal, NULL); 00043 } 00044 00045 STDMETHODIMP CComponentProxy::get_InteractiveMode(/*[out, retval]*/ VARIANT_BOOL *enabled) 00046 { 00047 CHECK_INIT; 00048 CComVariant venabled; 00049 venabled.Clear(); 00050 HRESULT hr = m_dispatch.GetPropertyByName(OLESTR("InteractiveMode"), &venabled); 00051 if (SUCCEEDED(hr)) { 00052 hr = venabled.ChangeType(VT_BOOL); 00053 if (SUCCEEDED(hr)) { 00054 *enabled = venabled.boolVal; 00055 } 00056 } 00057 return hr; 00058 } 00059 00060 STDMETHODIMP CComponentProxy::put_InteractiveMode(/*[in]*/ VARIANT_BOOL enabled) 00061 { 00062 CHECK_INIT; 00063 CComVariant venabled(enabled); 00064 return m_dispatch.PutPropertyByName(OLESTR("InteractiveMode"), &venabled); 00065 } 00066 00067 STDMETHODIMP CComponentProxy::get_ComponentName(/*[out, retval]*/ BSTR *pVal) 00068 { 00069 CHECK_INIT; 00070 CComVariant vval; 00071 vval.Clear(); 00072 HRESULT hr = m_dispatch.GetPropertyByName(OLESTR("ComponentName"), &vval); 00073 if (SUCCEEDED(hr)) { 00074 hr = vval.ChangeType(VT_BSTR); 00075 if (SUCCEEDED(hr)) { 00076 CComBSTR bstr(vval.bstrVal); 00077 *pVal = bstr.Detach(); 00078 } 00079 } 00080 return hr; 00081 } 00082 00083 STDMETHODIMP CComponentProxy::get_ComponentType(/*[out, retval]*/ componenttype_enum *t) 00084 { 00085 CHECK_INIT; 00086 CComVariant vval; 00087 vval.Clear(); 00088 HRESULT hr = m_dispatch.GetPropertyByName(OLESTR("ComponentType"), &vval); 00089 if (SUCCEEDED(hr)) { 00090 hr = vval.ChangeType(VT_I4); 00091 if (SUCCEEDED(hr)) { 00092 *t = (componenttype_enum)vval.lVal; 00093 } 00094 } 00095 return hr; 00096 } 00097 00098 STDMETHODIMP CComponentProxy::get_Paradigm(/*[out, retval]*/ BSTR *pVal) 00099 { 00100 CHECK_INIT; 00101 CComVariant vval; 00102 vval.Clear(); 00103 HRESULT hr = m_dispatch.GetPropertyByName(OLESTR("Paradigm"), &vval); 00104 if (SUCCEEDED(hr)) { 00105 hr = vval.ChangeType(VT_BSTR); 00106 if (SUCCEEDED(hr)) { 00107 CComBSTR bstr(vval.bstrVal); 00108 *pVal = bstr.Detach(); 00109 } 00110 } 00111 return hr; 00112 } 00113 00114 // IMgaComponentEx implementation 00115 STDMETHODIMP CComponentProxy::InvokeEx(/*[in]*/ IMgaProject *project, /*[in]*/ IMgaFCO *currentobj, /*[in,out]*/ IMgaFCOs *selectedobjs, /*[in]*/ long param) 00116 { 00117 CHECK_INIT; 00118 CComVariant varArgs[4]; 00119 varArgs[3] = project; 00120 varArgs[2] = currentobj; 00121 varArgs[1] = selectedobjs; 00122 varArgs[0] = param; 00123 return m_dispatch.InvokeN(OLESTR("InvokeEx"), &varArgs[0], 4, NULL); 00124 } 00125 00126 STDMETHODIMP CComponentProxy::ObjectsInvokeEx(/*[in]*/ IMgaProject *project, /*[in]*/ IMgaObject *currentobj, /*[in,out]*/ IMgaObjects *selectedobjs, /*[in]*/ long param) 00127 { 00128 CHECK_INIT; 00129 CComVariant varArgs[4]; 00130 varArgs[3] = project; 00131 varArgs[2] = currentobj; 00132 varArgs[1] = selectedobjs; 00133 varArgs[0] = param; 00134 return m_dispatch.InvokeN(OLESTR("ObjectsInvokeEx"), &varArgs[0], 4, NULL); 00135 } 00136 00137 STDMETHODIMP CComponentProxy::get_ComponentProgID(/*[out, retval]*/ BSTR *pVal) 00138 { 00139 CHECK_INIT; 00140 CComVariant vval; 00141 vval.Clear(); 00142 HRESULT hr = m_dispatch.GetPropertyByName(OLESTR("ComponentProgID"), &vval); 00143 if (SUCCEEDED(hr)) { 00144 hr = vval.ChangeType(VT_BSTR); 00145 if (SUCCEEDED(hr)) { 00146 CComBSTR bstr(vval.bstrVal); 00147 *pVal = bstr.Detach(); 00148 } 00149 } 00150 return hr; 00151 } 00152 00153 STDMETHODIMP CComponentProxy::put_ComponentParameter(/*[in]*/ BSTR name, /*[in]*/ VARIANT newVal) 00154 { 00155 CHECK_INIT; 00156 CComVariant vname(name); 00157 return m_dispatch.Invoke2(OLESTR("GetComponentParameter"), &vname, &newVal); 00158 } 00159 00160 STDMETHODIMP CComponentProxy::get_ComponentParameter(/*[in]*/ BSTR name, /*[out, retval]*/ VARIANT *pVal) 00161 { 00162 CHECK_INIT; 00163 ::VariantInit(pVal); 00164 CComVariant vname(name); 00165 return m_dispatch.Invoke1(OLESTR("GetComponentParameter"), &vname, pVal); 00166 } 00167 00168 // IGMEVersionInfo implementation 00169 STDMETHODIMP CComponentProxy::get_version(/*[out, retval]*/ GMEInterfaceVersion_enum *pVal) 00170 { 00171 CHECK_INIT; 00172 CComVariant vval; 00173 vval.Clear(); 00174 HRESULT hr = m_dispatch.GetPropertyByName(OLESTR("Version"), &vval); 00175 if (SUCCEEDED(hr)) { 00176 hr = vval.ChangeType(VT_I4); 00177 if (SUCCEEDED(hr)) { 00178 *pVal = (GMEInterfaceVersion_enum)vval.lVal; 00179 if (*pVal == GMEInterfaceVersion_None) { 00180 *pVal = GMEInterfaceVersion_Current; 00181 } 00182 } 00183 } 00184 return hr; 00185 } 00186