VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/win/VBoxComEvents.cpp@ 62585

Last change on this file since 62585 was 62468, checked in by vboxsync, 9 years ago

Main: scm

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: VBoxComEvents.cpp 62468 2016-07-22 18:01:39Z vboxsync $ */
2/** @file
3 *
4 * COM Events Helper routines.
5 */
6
7/*
8 * Copyright (C) 2010-2016 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "VBoxComEvents.h"
20// for IIDs
21#include "VirtualBoxImpl.h"
22
23ComEventsHelper::ComEventsHelper()
24{
25}
26
27ComEventsHelper::~ComEventsHelper()
28{
29}
30
31HRESULT ComEventsHelper::init(const com::Guid &aGuid)
32{
33 HRESULT hr = 0;
34 ComPtr<ITypeLib> ptlib;
35 ComPtr<ITypeInfo> ptinfo;
36 int i;
37
38
39 hr = ::LoadRegTypeLib(LIBID_VirtualBox, kTypeLibraryMajorVersion, kTypeLibraryMinorVersion, LOCALE_SYSTEM_DEFAULT, ptlib.asOutParam());
40 if (FAILED(hr))
41 return hr;
42
43 hr = ptlib->GetTypeInfoOfGuid(aGuid.ref(), ptinfo.asOutParam());
44 if (FAILED(hr))
45 return hr;
46
47 TYPEATTR *pta;
48 hr = ptinfo->GetTypeAttr(&pta);
49 if (FAILED(hr))
50 return hr;
51
52 int cFuncs = pta->cFuncs;
53
54 for (i = 0; i < cFuncs; i++)
55 {
56 FUNCDESC *pfd;
57 DWORD hContext; // help context
58 BSTR fName;
59
60 hr = ptinfo->GetFuncDesc(i, &pfd);
61 if (FAILED(hr))
62 break;
63
64 hr = ptinfo->GetDocumentation(pfd->memid, &fName, NULL, &hContext, NULL);
65 if (FAILED(hr))
66 {
67 ptinfo->ReleaseFuncDesc(pfd);
68 break;
69 }
70
71 /* We only allow firing event callbacks */
72 if (_wcsnicmp(fName, L"On", 2) == 0)
73 {
74 DISPID did;
75
76 hr = ::DispGetIDsOfNames(ptinfo, &fName, 1, &did);
77 evMap.insert(ComEventsMap::value_type(com::Utf8Str(fName), did));
78
79 }
80 SysFreeString(fName);
81
82 ptinfo->ReleaseFuncDesc(pfd);
83 }
84 ptinfo->ReleaseTypeAttr(pta);
85
86 return hr;
87}
88
89HRESULT ComEventsHelper::lookup(com::Utf8Str &aName, DISPID *did)
90{
91 ComEventsMap::const_iterator it = evMap.find(aName);
92
93 if (it != evMap.end())
94 {
95 *did = it->second;
96 return S_OK;
97 }
98 else
99 {
100 *did = 0;
101 return VBOX_E_OBJECT_NOT_FOUND;
102 }
103}
104
105
106HRESULT ComEventsHelper::fire(IDispatch *aObj, ComEventDesc &event, tagVARIANT *result)
107{
108 int argc = event.mArgc;
109 tagVARIANT *args = event.mArgs;
110 DISPPARAMS disp = { args, NULL, argc, 0};
111 DISPID dispid;
112
113 HRESULT hr = lookup(event.mName, &dispid);
114
115 if (FAILED(hr))
116 return hr;
117
118 hr = aObj->Invoke(dispid, IID_NULL,
119 LOCALE_USER_DEFAULT,
120 DISPATCH_METHOD,
121 &disp, result,
122 NULL, NULL);
123
124 return hr;
125}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette