我该怎么写代码使用这个组件中的事件接口和主接口中的方法?????(200分)

  • 主题发起人 主题发起人 giscom
  • 开始时间 开始时间
G

giscom

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是组件引入时产生的包装文件:
// ************************************************************************ //
// WARNING
// -------
// The types declared in this file were generated from data read from a
// Type Library. If this type library is explicitly or indirectly (via
// another type library referring to this type library) re-imported, or the
// 'Refresh' command of the Type Library Editor activated while editing the
// Type Library, the contents of this file will be regenerated and all
// manual modifications will be lost.
// ************************************************************************ //
// C++ TLBWRTR : $Revision: 1.134.1.39 $
// File generated on 2002-4-9 15:25:29 from Type Library described below.
// ************************************************************************ //
// Type Lib: E:/PLUS_D~1/20020405/datacoll.dll (1)
// IID/LCID: {55217BF8-44A4-4E8C-8183-E56C6804EF5E}/0
// Helpfile:
// DepndLst:
// (1) v2.0 stdole, (C:/WINNT/System32/stdole2.tlb)
// (2) v4.0 StdVCL, (C:/WINNT/System32/STDVCL40.DLL)
// ************************************************************************ //
#ifndef __DATACOLLLib_TLB_h__
#define __DATACOLLLib_TLB_h__
#pragma option push -b -w-inl
#include <utilcls.h>
#if !defined(__UTILCLS_H_VERSION) || (__UTILCLS_H_VERSION < 0x0500)
//
// The code generated by the TLIBIMP utility or the Import|TypeLibrary
// and Import|ActiveX feature of C++Builder rely on specific versions of
// the header file UTILCLS.H found in the INCLUDE/VCL directory. If an
// older version of the file is detected, you probably need an update/patch.
//
#error "This file requires a newer version of the header UTILCLS.H" /
"You need to apply an update/patch to your copy of C++Builder"
#endif
#include <olectl.h>
#include <ocidl.h>
#if defined(USING_ATLVCL) || defined(USING_ATL)
#if !defined(__TLB_NO_EVENT_WRAPPERS)
#include <atl/atlmod.h>
#endif
#endif

// *********************************************************************//
// Forward reference of some VCL types (to avoid including STDVCL.HPP)
// *********************************************************************//
namespace Stdvcl {class IStrings;
class IStringsDisp;}
using namespace Stdvcl;
typedef TComInterface<IStrings> IStringsPtr;
typedef TComInterface<IStringsDisp> IStringsDispPtr;
namespace Datacolllib_tlb
{
// *********************************************************************//
// HelpString: datacoll 1.0 Type Library
// Version: 1.0
// *********************************************************************//

// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLSID_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
extern __declspec (package) const GUID LIBID_DATACOLLLib;
extern __declspec (package) const GUID DIID__IPlusSnmpEvents;
extern __declspec (package) const GUID IID_IPlusSnmp;
extern __declspec (package) const GUID CLSID_PlusSnmp;
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
interface DECLSPEC_UUID("{6A0806FE-2031-4649-AD5D-D4DA1BB7EBA5}") _IPlusSnmpEvents;
typedef TComInterface<_IPlusSnmpEvents, &amp;DIID__IPlusSnmpEvents> _IPlusSnmpEventsPtr;
interface DECLSPEC_UUID("{EEB8BCDA-F437-4FAB-82F8-2CE97D6F98DF}") IPlusSnmp;
typedef TComInterface<IPlusSnmp, &amp;IID_IPlusSnmp> IPlusSnmpPtr;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
//
// The LIBID_OF_ macro(s) map a LIBID_OF_CoClassName to the GUID of this
// TypeLibrary. It simplifies the updating of macros when CoClass name
// change.
// *********************************************************************//
typedef IPlusSnmp PlusSnmp;
typedef IPlusSnmpPtr PlusSnmpPtr;
#define LIBID_OF_PlusSnmp (&amp;LIBID_DATACOLLLib)
// *********************************************************************//
// Interface: _IPlusSnmpEvents
// Flags: (4096) Dispatchable
// GUID: {6A0806FE-2031-4649-AD5D-D4DA1BB7EBA5}
// *********************************************************************//
interface _IPlusSnmpEvents : public TDispWrapper<IDispatch>
{
HRESULT __fastcall GetTrap(BSTR IP/*[in]*/, int AlarmID/*[in]*/, BSTR Usr/*[in]*/,
int Port/*[in]*/, BSTR State/*[in]*/, BSTR Desc/*[in]*/)
{
_TDispID _dispid(/* GetTrap */ DISPID(1));
TAutoArgs<6> _args;
_args[1] = IP /*[VT_BSTR:0]*/;
_args[2] = AlarmID /*[VT_INT:0]*/;
_args[3] = Usr /*[VT_BSTR:0]*/;
_args[4] = Port /*[VT_INT:0]*/;
_args[5] = State /*[VT_BSTR:0]*/;
_args[6] = Desc /*[VT_BSTR:0]*/;
return OleFunction(_dispid, _args);
}

};
// *********************************************************************//
// Interface: IPlusSnmp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {EEB8BCDA-F437-4FAB-82F8-2CE97D6F98DF}
// *********************************************************************//
interface IPlusSnmp : public IDispatch
{
public:
virtual HRESULT STDMETHODCALLTYPE GetSysInfo(BSTR IP/*[in]*/, BSTR* SysName/*[out]*/,
BSTR* SysDesc/*[out]*/, BSTR* SysMode/*[out]*/,
int* PortNumer/*[out]*/, long* bOK/*[out,retval]*/) = 0;
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
long __fastcall GetSysInfo(BSTR IP/*[in]*/, BSTR* SysName/*[out]*/, BSTR* SysDesc/*[out]*/,
BSTR* SysMode/*[out]*/, int* PortNumer/*[out]*/)
{
long bOK;
OLECHECK(this->GetSysInfo(IP, SysName, SysDesc, SysMode, PortNumer, (long*)&amp;bOK));
return bOK;
}
#endif // __TLB_NO_INTERFACE_WRAPPERS
};
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
// *********************************************************************//
// DispIntf: _IPlusSnmpEvents
// Flags: (4096) Dispatchable
// GUID: {6A0806FE-2031-4649-AD5D-D4DA1BB7EBA5}
// *********************************************************************//
template <class T>
class _IPlusSnmpEventsDispT : public TAutoDriver<_IPlusSnmpEvents>
{
public:
_IPlusSnmpEventsDispT(){}
void Attach(LPUNKNOWN punk)
{ m_Dispatch = static_cast<T*>(punk);
}
HRESULT __fastcall GetTrap(BSTR IP/*[in]*/, int AlarmID/*[in]*/, BSTR Usr/*[in]*/,
int Port/*[in]*/, BSTR State/*[in]*/, BSTR Desc/*[in]*/);
};
typedef _IPlusSnmpEventsDispT<_IPlusSnmpEvents> _IPlusSnmpEventsDisp;
// *********************************************************************//
// SmartIntf: TCOMIPlusSnmp
// Interface: IPlusSnmp
// *********************************************************************//
template <class T /* IPlusSnmp */ >
class TCOMIPlusSnmpT : public TComInterface<IPlusSnmp>, public TComInterfaceBase<IUnknown>
{
public:
TCOMIPlusSnmpT() {}
TCOMIPlusSnmpT(IPlusSnmp *intf, bool addRef = false) : TComInterface<IPlusSnmp>(intf, addRef) {}
TCOMIPlusSnmpT(const TCOMIPlusSnmpT&amp;
src) : TComInterface<IPlusSnmp>(src) {}
TCOMIPlusSnmpT&amp;
operator=(const TCOMIPlusSnmpT&amp;
src) { Bind(src, true);
return *this;}
HRESULT __fastcall GetSysInfo(BSTR IP/*[in]*/, BSTR* SysName/*[out]*/,
BSTR* SysDesc/*[out]*/, BSTR* SysMode/*[out]*/,
int* PortNumer/*[out]*/, long* bOK/*[out,retval]*/);
};
typedef TCOMIPlusSnmpT<IPlusSnmp> TCOMIPlusSnmp;
// *********************************************************************//
// DispIntf: IPlusSnmp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {EEB8BCDA-F437-4FAB-82F8-2CE97D6F98DF}
// *********************************************************************//
template<class T>
class IPlusSnmpDispT : public TAutoDriver<IPlusSnmp>
{
public:
IPlusSnmpDispT(){}
IPlusSnmpDispT(IPlusSnmp *pintf)
{
TAutoDriver<IPlusSnmp>::Bind(pintf, false);
}
IPlusSnmpDispT(IPlusSnmpPtr pintf)
{
TAutoDriver<IPlusSnmp>::Bind(pintf, true);
}
IPlusSnmpDispT&amp;
operator=(IPlusSnmp *pintf)
{
TAutoDriver<IPlusSnmp>::Bind(pintf, false);
return *this;
}
IPlusSnmpDispT&amp;
operator=(IPlusSnmpPtr pintf)
{
TAutoDriver<IPlusSnmp>::Bind(pintf, true);
return *this;
}
HRESULT BindDefault()
{
return OLECHECK(Bind(CLSID_PlusSnmp));
}
HRESULT BindRunning()
{
return BindToActive(CLSID_PlusSnmp);
}
HRESULT __fastcall GetSysInfo(BSTR IP/*[in]*/, BSTR* SysName/*[out]*/,
BSTR* SysDesc/*[out]*/, BSTR* SysMode/*[out]*/,
int* PortNumer/*[out]*/, long* bOK/*[out,retval]*/);
};
typedef IPlusSnmpDispT<IPlusSnmp> IPlusSnmpDisp;
// *********************************************************************//
// DispIntf: _IPlusSnmpEvents
// Flags: (4096) Dispatchable
// GUID: {6A0806FE-2031-4649-AD5D-D4DA1BB7EBA5}
// *********************************************************************//
template <class T> HRESULT __fastcall
_IPlusSnmpEventsDispT<T>::GetTrap(BSTR IP/*[in]*/, int AlarmID/*[in]*/, BSTR Usr/*[in]*/,
int Port/*[in]*/, BSTR State/*[in]*/, BSTR Desc/*[in]*/)
{
_TDispID _dispid(/* GetTrap */ DISPID(1));
TAutoArgs<6> _args;
_args[1] = IP /*[VT_BSTR:0]*/;
_args[2] = AlarmID /*[VT_INT:0]*/;
_args[3] = Usr /*[VT_BSTR:0]*/;
_args[4] = Port /*[VT_INT:0]*/;
_args[5] = State /*[VT_BSTR:0]*/;
_args[6] = Desc /*[VT_BSTR:0]*/;
return OleFunction(_dispid, _args);
}
// *********************************************************************//
// SmartIntf: TCOMIPlusSnmp
// Interface: IPlusSnmp
// *********************************************************************//
template <class T> HRESULT __fastcall
TCOMIPlusSnmpT<T>::GetSysInfo(BSTR IP/*[in]*/, BSTR* SysName/*[out]*/, BSTR* SysDesc/*[out]*/,
BSTR* SysMode/*[out]*/, int* PortNumer/*[out]*/,
long* bOK/*[out,retval]*/)
{
return (*this)->GetSysInfo(IP, SysName, SysDesc, SysMode, PortNumer, bOK);
}
template <class T> long __fastcall
TCOMIPlusSnmpT<T>::GetSysInfo(BSTR IP/*[in]*/, BSTR* SysName/*[out]*/, BSTR* SysDesc/*[out]*/,
BSTR* SysMode/*[out]*/, int* PortNumer/*[out]*/)
{
long bOK;
OLECHECK(this->GetSysInfo(IP, SysName, SysDesc, SysMode, PortNumer, (long*)&amp;bOK));
return bOK;
}
// *********************************************************************//
// The following typedefs expose classes (named CoCoClassName) that
// provide static Create() and CreateRemote(LPWSTR machineName) methods
// for creating an instance of an exposed object. These functions can
// be used by client wishing to automate CoClasses exposed by this
// typelibrary.
// *********************************************************************//
// *********************************************************************//
// COCLASS DEFAULT INTERFACE CREATOR
// CoClass : PlusSnmp
// Interface: TCOMIPlusSnmp
// *********************************************************************//
typedef TCoClassCreatorT<TCOMIPlusSnmp, IPlusSnmp, &amp;CLSID_PlusSnmp, &amp;IID_IPlusSnmp> CoPlusSnmp;
#endif // __TLB_NO_INTERFACE_WRAPPERS

#if !defined(__TLB_NO_EVENT_WRAPPERS) &amp;&amp;
defined(USING_ATLVCL)
// *********************************************************************//
// CONNECTIONPOINT/EVENT PROXY
// CoClass : PlusSnmp
// Event Interface : _IPlusSnmpEvents
// *********************************************************************//
template <class T>
class TEvents_PlusSnmp : public IConnectionPointImpl<T,
&amp;DIID__IPlusSnmpEvents,
CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE> >
{
public:
HRESULT Fire_GetTrap(BSTR IP, int AlarmID, BSTR Usr, int Port, BSTR State, BSTR Desc);
protected:
_IPlusSnmpEventsDisp m_EventIntfObj;
};
template <class T> HRESULT
TEvents_PlusSnmp<T>::Fire_GetTrap(BSTR IP, int AlarmID, BSTR Usr, int Port, BSTR State, BSTR Desc)
{
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.GetTrap(IP, AlarmID, Usr, Port, State, Desc);
m_EventIntfObj.Attach(0);
}
pp++;
}
pT->Unlock();
}
#endif // __TLB_NO_EVENT_WRAPPERS
};
// namespace Datacolllib_tlb
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Datacolllib_tlb;
#endif
#pragma option pop
#endif // __DATACOLLLib_TLB_h__
 
用CB建立一个Application后,选择Project菜单,选Import Type Library,在选框中选中
你的接口名称,点击Create Unit按钮,CB就会为你建立相关的接口调用单元,将单元文件
存在$(BCB)CBuilder6/Imports目录下,将将该文件包含到你的项目中。
下一步,点击File菜单,选择Include Unit Hdr来包含刚才导入的接口调用单元,最后就
是写接口的调用代码了:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TCOMIPlusSnmp Obj1;
WideString wIP,wSysName,wSysDesc,wSysMode;
int iPortNumber;
long bOK=0;
Obj1 = CoPlusSnmp::Create();
wIP = "10.60.33.2";
Obj1->GetSysInfo(wIP, &amp;wSysName, &amp;wSysDesc, &amp;wSysMode, &amp;iPortNumber, &amp;bOK);
//或:
//bOK = Obj1.GetSysInfo(wIP, &amp;wSysName, &amp;wSysDesc, &amp;sSysMode, &amp;iPortNumber);
ShowMessage(IntToStr(bOK));
}
 
后退
顶部