-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathISelfScript.cpp
60 lines (53 loc) · 1.47 KB
/
ISelfScript.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
// ISelfScript.cpp: implementation of the CISelfScript class.
#include "stdafx.h"
#include "configsvcimpl.h"
#include "ISelfScript.h"
#include "scripting.h"
ITypeInfo* CISelfScript::m_pTypeInfo=NULL;
CISelfScript::CISelfScript()
{
}
CISelfScript::~CISelfScript()
{
ResetAdded();
}
STDMETHODIMP CISelfScript::get_Name(BSTR *pVal)
{
if(IsBadWritePtr(pVal,sizeof(*pVal)))
return E_POINTER;
*pVal=m_pScript->m_ScriptName.AllocSysString();
return S_OK;
}
STDMETHODIMP CISelfScript::AddNamedItem(BSTR Name,IDispatch *Object,VARIANT_BOOL AsGlobal)
{
CString name=(LPCTSTR)_bstr_t(Name);
if(name.IsEmpty())
return SetError(E_INVALIDARG,"Ïóñòîå èìÿ");
name.MakeLower();
void* pVal;
if(m_Objects.Lookup(name,pVal))
return SetError(E_INVALIDARG,"Èìÿ \"%s\" óæå çàðåãèñòðèðîâàíî",(LPCTSTR)_bstr_t(Name));
m_Objects[name]=Object;
Object->AddRef();
m_pScript->m_pEngine->SetScriptState(SCRIPTSTATE_DISCONNECTED);
HRESULT hr=m_pScript->m_pEngine->AddNamedItem(Name,SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|(AsGlobal?SCRIPTITEM_GLOBALMEMBERS:0));
m_pScript->m_pEngine->SetScriptState(SCRIPTSTATE_CONNECTED);
if(S_OK!=hr)
{
m_Objects.RemoveKey(name);
Object->Release();
return hr;
}
return S_OK;
}
void CISelfScript::ResetAdded()
{
IDispatch* pDisp;
CString name;
for(POSITION pos=m_Objects.GetStartPosition();pos;)
{
m_Objects.GetNextAssoc(pos,name,(void*&)pDisp);
pDisp->Release();
}
m_Objects.RemoveAll();
}