-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMyScriptSite.h
More file actions
87 lines (81 loc) · 2.27 KB
/
Copy pathCMyScriptSite.h
File metadata and controls
87 lines (81 loc) · 2.27 KB
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
#pragma once
#include <windows.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlcomcli.h>
#include <ScriptSite.h>
#include "beeper2026_i.h"
#include "ScriptHost5.h"
//void GetScriptEngines(CSimpleArray<CString>& vv);
class CMyScriptSite :
public CComObjectRootEx<CComSingleThreadModel>,
public CScriptSiteImpl
{
CComQIPtr<IBeeperObj2026> m_spBeeper;
CComQIPtr<IScriptHostApp> m_spApp;
public:
CMyScriptSite()
{
}
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CMyScriptSite)
COM_INTERFACE_ENTRY(IActiveScriptSite)
COM_INTERFACE_ENTRY(IActiveScriptSiteWindow)
END_COM_MAP()
HRESULT Init(CComPtr<IDispatch> spApp,CComPtr<IDispatch> spBeeper,LPCTSTR lang,HWND hwnd) {
m_spBeeper = spBeeper;
m_spApp = spApp;
HRESULT hr = Initiate(lang, hwnd);
if (SUCCEEDED(hr)) {
//hr = AddObject(_T("beeper"), FALSE, TRUE);
hr = AddObject(_T("app"), FALSE, TRUE);
}
ATLASSERT(SUCCEEDED(hr));
return hr;
}
STDMETHOD(LookupNamedItem)(LPCOLESTR pstrName, LPUNKNOWN* ppunkItem)
{
CComBSTR name = pstrName;
HRESULT hr = TYPE_E_ELEMENTNOTFOUND;
/*
if (name == OLESTR("beeper")) {
ATLASSERT(ppunkItem != NULL);
hr = m_spBeeper->QueryInterface(IID_IBeeperObj2026,(void **) ppunkItem);
}
*/
if (name == OLESTR("app")) {
ATLASSERT(ppunkItem != NULL);
hr = m_spApp->QueryInterface(IID_IScriptHostApp, (void**)ppunkItem);
}
return hr;
}
STDMETHOD(GetItemInfo)(LPCOLESTR pstrName, DWORD dwMask, LPUNKNOWN* ppunkItem, LPTYPEINFO* ppTypeInfo)
{
CComPtr<IUnknown> spUnk;
HRESULT hr = LookupNamedItem(pstrName, &spUnk);
if (SUCCEEDED(hr)) {
if (dwMask & SCRIPTINFO_ITYPEINFO) {
CComPtr<ITypeInfo> spTI;
CComQIPtr<IProvideClassInfo> spPCI = spUnk;
if (!!spPCI) {
// Got IProvideClassInfo interface so use it
hr = spPCI->GetClassInfo(&spTI);
spPCI.Release();
}
else {
// Try for IDispatch::GetTypeInfo
CComQIPtr<IDispatch> spDisp = spUnk;
if (!!spDisp) {
hr = spDisp->GetTypeInfo(0, LOCALE_SYSTEM_DEFAULT, &spTI);
spDisp.Release();
}
}
*ppTypeInfo = spTI.Detach();
}
if (dwMask & SCRIPTINFO_IUNKNOWN) {
hr = spUnk->QueryInterface(IID_IUnknown, (void **)ppunkItem);
}
}
return hr;
}
};