forked from MicrosoftEdge/WebView2Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteObjectSampleImpl.cpp
More file actions
86 lines (73 loc) · 2.62 KB
/
RemoteObjectSampleImpl.cpp
File metadata and controls
86 lines (73 loc) · 2.62 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
// Copyright (C) Microsoft Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "stdafx.h"
#include "RemoteObjectSampleImpl.h"
RemoteObjectSample::RemoteObjectSample(RemoteObjectSample::RunCallbackAsync runCallbackAsync)
: m_propertyValue(L"Example Property String Value"), m_runCallbackAsync(runCallbackAsync)
{
}
STDMETHODIMP RemoteObjectSample::MethodWithParametersAndReturnValue(
BSTR stringParameter, INT integerParameter, BSTR* stringResult)
{
std::wstring result = L"MethodWithParametersAndReturnValue(";
result += stringParameter;
result += L", ";
result += std::to_wstring(integerParameter);
result += L") called.";
*stringResult = SysAllocString(result.c_str());
return S_OK;
}
STDMETHODIMP RemoteObjectSample::get_Property(BSTR* stringResult)
{
*stringResult = SysAllocString(m_propertyValue.c_str());
return S_OK;
}
STDMETHODIMP RemoteObjectSample::put_Property(BSTR stringValue)
{
m_propertyValue = stringValue;
return S_OK;
}
STDMETHODIMP RemoteObjectSample::CallCallbackAsynchronously(IDispatch* callbackParameter)
{
wil::com_ptr<IDispatch> callbackParameterForCapture = callbackParameter;
m_runCallbackAsync([callbackParameterForCapture]() -> void {
callbackParameterForCapture->Invoke(
DISPID_UNKNOWN, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, nullptr, nullptr,
nullptr, nullptr);
});
return S_OK;
}
STDMETHODIMP RemoteObjectSample::GetTypeInfoCount(UINT* pctinfo)
{
*pctinfo = 1;
return S_OK;
}
STDMETHODIMP RemoteObjectSample::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
{
if (0 != iTInfo)
{
return TYPE_E_ELEMENTNOTFOUND;
}
if (!m_typeLib)
{
RETURN_IF_FAILED(LoadTypeLib(L"WebView2APISample.tlb", &m_typeLib));
}
return m_typeLib->GetTypeInfoOfGuid(__uuidof(IRemoteObjectSample), ppTInfo);
}
STDMETHODIMP RemoteObjectSample::GetIDsOfNames(
REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
{
wil::com_ptr<ITypeInfo> typeInfo;
RETURN_IF_FAILED(GetTypeInfo(0, lcid, &typeInfo));
return typeInfo->GetIDsOfNames(rgszNames, cNames, rgDispId);
}
STDMETHODIMP RemoteObjectSample::Invoke(
DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
wil::com_ptr<ITypeInfo> typeInfo;
RETURN_IF_FAILED(GetTypeInfo(0, lcid, &typeInfo));
return typeInfo->Invoke(
this, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
}