i'm use vc , there is some code snippet.
class IwodTelnetDLXCom : public COleDispatchDriver
IwodTelnetDLXCom::IwodTelnetDLXCom()
{
// OLE init
OleInitialize(NULL);
// create wodTelnetDLXCom
if (!CreateDispatch( WeOnlyDo.wodTelnetDLXCom.1 ,NULL))
{
AfxMessageBox( Could not create wodTelnetDLX object ,MB_OK,0);
return;
}
// attach events
m_pTelnetDLXEvents = new CEventSink;
LPUNKNOWN pUnknown= m_pTelnetDLXEvents->GetIDispatch(FALSE);
AfxConnectionAdvise(m_lpDispatch,DIID__IwodTelnetDLXComEvents,pUnknown,FALSE,&m_dCookie);
m_pTelnetDLXEvents->m_pCtrl= this;
}
IwodTelnetDLXCom::~IwodTelnetDLXCom()
{
LPUNKNOWN pUnknown = m_pTelnetDLXEvents->GetIDispatch(FALSE);
AfxConnectionUnadvise( m_lpDispatch,DIID__IwodTelnetDLXComEvents,pUnknown,FALSE,m_dCookie);
ReleaseDispatch();
if(m_pTelnetDLXEvents)
{
m_pTelnetDLXEvents->m_pCtrl = NULL;
delete m_pTelnetDLXEvents;
m_pTelnetDLXEvents = NULL;
}
OleUninitialize();
}
IwodTelnetDLXCom::connect( string ipaddress )
{
SetHostname( ipaddress );
SetPort( nRemotePort );
SetBlocking( FALSE );
SetTimeout( 0 );
SetProtocol( 1 );
try
{
VARIANT var;
var.vt = VT_ERROR;
Connect( var , var , var );
}
catch (COleDispatchException *e)
{
//do something
}
}
i want to get many router's config file using command show run of telnet.so i create n instance of IwodTelnetDLXCom;
if n less and equal 12 , evertyting is fine; if n==13, sometimes crash.if n > 13 , always crash.
IwodTelnetDLXCom aa[n];
for( int i = 0 ; i < n; i++ )
{
aa.connect( ipaddress );
}
when connected sucessfully , application trigger received event.
the folowing is my rece function 's code
VARIANT var;
var.vt = VT_ERROR;
VARIANT var2;
var2.vt = VT_I2;
var2.iVal = VT_BSTR;
var2 = Receive(var, var2);
char* lpszText = _com_util::ConvertBSTRToString( var2.bstrVal );
SaveFile( filename , lpszText )
i want to know what's wrong of my code , i hope you can help me , thanks