Board index » cppbuilder » Error when using Importing Type Library on COM object
|
Mischa Simmonds
CBuilder Developer |
Error when using Importing Type Library on COM object2007-09-27 09:11:22 AM cppbuilder84 The import type library creates the following code which will not compile due to "Error: E2192 Too few parameters in call". So I have modified it by adding "TVariant(params[1])". However, at runtime it raises an exception System::DynArrayOutOfRange and I am unable to use this event. I have looked through examples from other imports I have done and don't see any event classes that contain [out,retval] parameters, so wondering if the problem could be related to that? Hopefully someone can help me before I pull all of my hair out!! ;) Thanks Extract from Viewpoint_OCX.h showing what the import type library wizard creates and what I modified // *********************************************************************// void __fastcall TPartitionManager::InvokeEvent(int id, Oleserver::TVariantArray& params) { switch(id) { case 6: { if (OnPreTransmit) { // (OnPreTransmit)(this, TVariant(params[0])); //Error: E2192 Too few parameters in call (OnPreTransmit)(this, TVariant(params[0]),TVariant(params[1])); //Compiles with this change } break; } default: break; } } However, this function raises exception class System::DynArrayOutOfRange with message'Exception Object Address:0xD158d2' in the following function within sysdyn.h .... // *********************************************************************// template <class T>T& DynamicArray<T>::operator[](int index) { if (index < 0 || index>= this->Length) throw DynArrayOutOfRange(index, this->Length); if (!Data) throw DynArrayNullData(); return *(Data + index); } The COM object work fine within javascript in HTML... // *********************************************************************// <SCRIPT> var pm = new ActiveXObject("galileo.PartitionManager"); var sink = new ActiveXObject("GIUtils.sink"); function OnPreTransmit(s) { if(entry_text.value.length) { return entry_text.value; } else { return s; } } function Connect() { sink.PreTransmit = OnPreTransmit; sink.Advise(pm); } </SCRIPT> The following are extracts from Viewpoint_TLB.h where PreTransmit is defined... // *********************************************************************// interface IDispPartitionManagerEvents : public TDispWrapper<IDispatch> { HRESULT __fastcall PreTransmit(BSTR Entry/*[in]*/, BSTR* updatedEntry/*[out,retval]*/) { _TDispID _dispid(/* PreTransmit */ DISPID(6)); TAutoArgs<1>_args; _args[1] = Entry /*[VT_BSTR:0]*/; return OutRetValSetterPtr(updatedEntry /*[VT_BSTR:1]*/, _args, OleFunction(_dispid, _args)); } BSTR __fastcall PreTransmit(BSTR Entry/*[in]*/) { BSTR updatedEntry; this->PreTransmit(Entry, (BSTR*)&updatedEntry); return updatedEntry; } }; // *********************************************************************// template <class T> class IDispPartitionManagerEventsDispT : public TAutoDriver<IDispPartitionManagerEvents> { public: IDispPartitionManagerEventsDispT(){} void Attach(LPUNKNOWN punk) { m_Dispatch = static_cast<T*>(punk); } HRESULT __fastcall PreTransmit(BSTR Entry/*[in]*/, BSTR* updatedEntry/*[out,retval]*/); BSTR __fastcall PreTransmit(BSTR Entry/*[in]*/); }; // *********************************************************************// template <class T>HRESULT __fastcall IDispPartitionManagerEventsDispT<T>::PreTransmit(BSTR Entry/*[in]*/, BSTR* updatedEntry/*[out,retval]*/) { _TDispID _dispid(/* PreTransmit */ DISPID(6)); TAutoArgs<1>_args; _args[1] = Entry /*[VT_BSTR:0]*/; return OutRetValSetterPtr(updatedEntry /*[VT_BSTR:1]*/, _args, OleFunction(_dispid, _args)); } template <class T>BSTR __fastcall IDispPartitionManagerEventsDispT<T>::PreTransmit(BSTR Entry/*[in]*/) { BSTR updatedEntry; this->PreTransmit(Entry, (BSTR*)&updatedEntry); return updatedEntry; } // *********************************************************************// template <class T> class TEvents_PartitionManager : public IConnectionPointImpl<T, &DIID_IDispPartitionManagerEvents, CComDynamicUnkArray<CONNECTIONPOINT_ARRAY_SIZE>> //CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE>> /* Note: if encountering problems with events, please change CComUnkArray to CComDynamicUnkArray in the line above. */ { public: HRESULT Fire_PreTransmit(BSTR Entry, BSTR* updatedEntry); protected: IDispPartitionManagerEventsDisp m_EventIntfObj; }; // *********************************************************************// template <class T>HRESULT TEvents_PartitionManager<T>::Fire_PreTransmit(BSTR Entry, BSTR* updatedEntry) { T * pT = (T*)this; pT->Lock(); IUnknown ** pp = m_vec.begin(); while (pp < m_vec.end()) { if (*pp != NULL) { m_EventIntfObj.Attach(*pp); m_EventIntfObj.PreTransmit(Entry, updatedEntry); m_EventIntfObj.Attach(0); } pp++; } pT->Unlock(); } |
