-
Notifications
You must be signed in to change notification settings - Fork 1
/
itemdisp.cpp
168 lines (161 loc) · 3.54 KB
/
itemdisp.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Copyright(c) 2000 arton
*
* You may distribute under the terms of either the GNU General Public
* License
*
*/
#include "stdafx.h"
#ifdef _MERGE_PROXYSTUB
#include "RScript.h"
#else
#include "GRScript.h"
#endif
#include "RScriptCore.h"
#include "ItemDisp.h"
IDispatch* CItemHolder::GetDispatch()
{
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
if (m_pGIPDispEx.IsOK())
{
IDispatchEx* p;
HRESULT hr = m_pGIPDispEx.Localize(&p);
return p;
}
if (m_pGIPDisp.IsOK())
{
IDispatch* p;
HRESULT hr = m_pGIPDisp.Localize(&p);
return p;
}
#endif
if (m_pDispEx)
{
m_pDispEx->AddRef();
return m_pDispEx;
}
if (m_pDisp)
{
m_pDisp->AddRef();
return m_pDisp;
}
return NULL;
}
CItemHolder::~CItemHolder()
{
Empty();
}
void CItemHolder::Empty()
{
if (m_pDispEx)
{
m_pDispEx->Release();
m_pDispEx = NULL;
}
if (m_pDisp)
{
m_pDisp->Release();
m_pDisp = NULL;
}
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
if (m_pGIPDispEx.IsOK())
{
m_pGIPDispEx.Unglobalize();
}
if (m_pGIPDisp.IsOK())
{
m_pGIPDisp.Unglobalize();
}
#endif
}
IDispatch* CItemHolder::GetDispatch(IActiveScriptSite* pSite, LPOLESTR pstrName, bool fSameApt)
{
IDispatchEx* pDispEx = m_pDispEx;
IDispatch* pDisp = m_pDisp;
ATLTRACE(_("CItemHolder::GetDispatch in Thread:%08X name=%ls sameptr=%d\n"), GetCurrentThreadId(), pstrName, fSameApt);
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
if (fSameApt)
{
#endif
if (pDisp == NULL && pDispEx == NULL)
{
ATLTRACE(_("CItemHolder::GetDispatch in Thread:%08X\n"), GetCurrentThreadId());
IUnknown* pUnk = NULL;
ITypeInfo* pTypeInfo = NULL;
HRESULT hr = pSite->GetItemInfo(pstrName, SCRIPTINFO_IUNKNOWN, &pUnk, &pTypeInfo);
if (hr == S_OK)
{
if (pTypeInfo) pTypeInfo->Release();
if (pUnk->QueryInterface(IID_IDispatchEx, (void**)&pDispEx) == S_OK)
{
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
HRESULT hr = m_pGIPDispEx.Globalize(pDispEx);
ATLTRACE(_T("Globalize Item = %08X\n"), hr);
#endif
m_pDispEx = pDispEx;
}
else
{
pDispEx = NULL;
if (pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp) == S_OK)
{
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
HRESULT hr = m_pGIPDisp.Globalize(pDisp);
ATLTRACE(_T("Globalize Item = %08X\n"), hr);
#endif
m_pDisp = pDisp;
}
}
pUnk->Release();
}
}
if (pDispEx)
{
pDispEx->AddRef();
}
else if (pDisp)
{
pDisp->AddRef();
}
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
}
else
{
if (m_pGIPDisp.IsOK() == false && m_pGIPDispEx.IsOK() == false)
{
ATLTRACE(_("CItemHolder::GetDispatch in Thread:%08X\n"), GetCurrentThreadId());
IUnknown* pUnk = NULL;
ITypeInfo* pTypeInfo = NULL;
HRESULT hr = pSite->GetItemInfo(pstrName, SCRIPTINFO_IUNKNOWN, &pUnk, &pTypeInfo);
if (hr == S_OK)
{
if (pTypeInfo) pTypeInfo->Release();
if (pUnk->QueryInterface(IID_IDispatchEx, (void**)&pDispEx) != S_OK)
{
pDispEx = NULL;
if (pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp) != S_OK)
{
pDisp = NULL;
}
}
pUnk->Release();
}
}
if (m_pGIPDispEx.IsOK())
{
IDispatchEx* p;
HRESULT hr = m_pGIPDispEx.Localize(&p);
ATLTRACE(_("Localize DispEx = %08X\n"), hr);
return p;
}
if (m_pGIPDisp.IsOK())
{
IDispatch* p;
HRESULT hr = m_pGIPDisp.Localize(&p);
ATLTRACE(_("Localize Disp = %08X\n"), hr);
return p;
}
}
#endif
return (pDispEx) ? pDispEx : pDisp;
}