-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEventCallableSDO.cpp
74 lines (62 loc) · 1.65 KB
/
EventCallableSDO.cpp
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
#include "stdafx.h"
#include "EventCallableSDO.h"
EventCallableSDO::EventCallableSDO(ScriptDrivenObject^ instance, LoadedModuleHandle module)
: ReflectableSDO(instance, module)
{
}
Object^ EventCallableSDO::InvokeInternal(String^ name,
System::Reflection::BindingFlags invokeAttr,
Binder^ binder,
Object^ target,
array<Object^>^ args,
System::Globalization::CultureInfo^ culture)
{
array<Object^>^ passedArgs = gcnew array<Object^>(args->Length);
array<IParamsWrapper^>^ wrappers = gcnew array<IParamsWrapper^>(args->Length);
try
{
Object^ result;
for (int i = 0; i < args->Length; i++)
{
IParamsWrapper^ wrapper = dynamic_cast<IParamsWrapper^>(args[i]);
IValue^ argValue;
if(wrapper != nullptr)
{
wrappers[i] = wrapper;
argValue = COMWrapperContext::CreateIValue(wrapper->val);
}
else
{
argValue = COMWrapperContext::CreateIValue(args[i]);
}
passedArgs[i] = Variable::CreateReference(Variable::Create(argValue));
}
result = ReflectableSDO::InvokeInternal(name, invokeAttr, binder, target, passedArgs, culture);
for (int i = 0; i < args->Length; i++)
{
IParamsWrapper^ wrapper = wrappers[i];
Object^ argValue = COMWrapperContext::MarshalIValue(safe_cast<IValue^>(passedArgs[i]));
if(wrapper != nullptr)
{
wrapper->val = argValue;
}
else
{
args[i] = passedArgs[i];
}
}
return result;
}
catch(Exception^ exc)
{
auto buf = stringBuf(exc->ToString());
MessageBox(0, buf, L"Error", MB_ICONERROR);
delete[] buf;
throw;
}
finally
{
delete[] passedArgs;
delete[] wrappers;
}
}