blob: 9287bae86e3f6c1840daacd25ed1565349b21f09 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Expression.cpp : implémentation de CExpression
#include "stdafx.h"
#include "Bus.h"
#include "Ivy.h"
#include "IvyApplication.h"
#include "Expression.h"
char * ConvBSTR( BSTR str );
BSTR ConvCSTR( const char *str );
// CExpression
STDMETHODIMP CExpression::Bind(char* regex, CBus* _bus)
{
if ( !_bus ) return E_FAIL;
bus = _bus;
bus->AddRef();
if ( id != -1 )
return E_FAIL;
if ( bus->bus )
id = bus->bus->BindMsg( regex, this );
else return E_FAIL;
return S_OK;
}
STDMETHODIMP CExpression::Unbind(void)
{
if ( !bus ) return E_FAIL;
if ( bus->bus && id != -1 )
{
bus->bus->UnbindMsg( id );
id = -1;
}
else return E_FAIL;
bus->Release();
return S_OK;
}
void CExpression::OnMessage(IvyApplication * app, int argc, const char ** argv)
{
BSTR appname = ConvCSTR( app->GetName() );
SAFEARRAY *pArrayVal = NULL;
HRESULT hr = S_OK;
// pour assurer la compatibilite avec VBSCript pouah horreur
//Create the safe array for the arguments string.
pArrayVal = SafeArrayCreateVector( VT_VARIANT, 0, argc );
if (!(pArrayVal == NULL) )
{
// Set the values for each element of the array
for( long i = 0 ; i < argc && SUCCEEDED( hr );i++)
{
hr = SafeArrayPutElement(pArrayVal, &i, new CComVariant(ConvCSTR(argv[i])));
}
}
VARIANT args;
args.vt = VT_ARRAY | VT_VARIANT;
V_ARRAY(&args) = pArrayVal;
Received( appname, args );
SafeArrayDestroy(pArrayVal);
}
// CExpression
CExpression::CExpression()
{
id = -1;
bus = 0;
ATLTRACE("CExpression created\n");
}
CExpression::~CExpression()
{
if ( id != -1 )
Unbind();
id = -1;
bus = 0;
ATLTRACE("CExpression destroyed\n");
}
|