Sync with trunk r65656.
[reactos.git] / base / applications / cmdutils / wscript / arguments.c
1 /*
2 * Copyright 2011 Michal Zietek
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include "wscript.h"
20
21 WCHAR **argums;
22 int numOfArgs;
23
24 static HRESULT WINAPI Arguments2_QueryInterface(IArguments2 *iface, REFIID riid, void **ppv)
25 {
26 WINE_TRACE("(%s %p)\n", wine_dbgstr_guid(riid), ppv);
27
28 if(IsEqualGUID(&IID_IUnknown, riid)
29 || IsEqualGUID(&IID_IDispatch, riid)
30 || IsEqualGUID(&IID_IArguments2, riid)) {
31 *ppv = iface;
32 return S_OK;
33 }
34
35 *ppv = NULL;
36 return E_NOINTERFACE;
37 }
38
39 static ULONG WINAPI Arguments2_AddRef(IArguments2 *iface)
40 {
41 return 2;
42 }
43
44 static ULONG WINAPI Arguments2_Release(IArguments2 *iface)
45 {
46 return 1;
47 }
48
49 static HRESULT WINAPI Arguments2_GetTypeInfoCount(IArguments2 *iface, UINT *pctinfo)
50 {
51 WINE_TRACE("(%p)\n", pctinfo);
52
53 *pctinfo = 1;
54 return S_OK;
55 }
56
57 static HRESULT WINAPI Arguments2_GetTypeInfo(IArguments2 *iface, UINT iTInfo, LCID lcid,
58 ITypeInfo **ppTInfo)
59 {
60 WINE_TRACE("(%x %x %p\n", iTInfo, lcid, ppTInfo);
61
62 ITypeInfo_AddRef(arguments_ti);
63 *ppTInfo = arguments_ti;
64 return S_OK;
65 }
66
67 static HRESULT WINAPI Arguments2_GetIDsOfNames(IArguments2 *iface, REFIID riid, LPOLESTR *rgszNames,
68 UINT cNames, LCID lcid, DISPID *rgDispId)
69 {
70 WINE_TRACE("(%s %p %d %x %p)\n", wine_dbgstr_guid(riid), rgszNames,
71 cNames, lcid, rgDispId);
72
73 return ITypeInfo_GetIDsOfNames(arguments_ti, rgszNames, cNames, rgDispId);
74 }
75
76 static HRESULT WINAPI Arguments2_Invoke(IArguments2 *iface, DISPID dispIdMember, REFIID riid,
77 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
78 EXCEPINFO *pExcepInfo, UINT *puArgErr)
79 {
80 WINE_TRACE("(%d %p %p)\n", dispIdMember, pDispParams, pVarResult);
81
82 return ITypeInfo_Invoke(arguments_ti, iface, dispIdMember, wFlags, pDispParams,
83 pVarResult, pExcepInfo, puArgErr);
84 }
85
86 static HRESULT WINAPI Arguments2_Item(IArguments2 *iface, LONG index, BSTR *out_Value)
87 {
88 WINE_TRACE("(%d %p)\n", index, out_Value);
89
90 if(index<0 || index >= numOfArgs)
91 return E_INVALIDARG;
92 if(!(*out_Value = SysAllocString(argums[index])))
93 return E_OUTOFMEMORY;
94
95 return S_OK;
96 }
97
98 static HRESULT WINAPI Arguments2_Count(IArguments2 *iface, LONG *out_Count)
99 {
100 WINE_TRACE("(%p)\n", out_Count);
101
102 *out_Count = numOfArgs;
103 return S_OK;
104 }
105
106 static HRESULT WINAPI Arguments2_get_length(IArguments2 *iface, LONG *out_Count)
107 {
108 WINE_TRACE("(%p)\n", out_Count);
109
110 *out_Count = numOfArgs;
111 return S_OK;
112 }
113
114 static const IArguments2Vtbl Arguments2Vtbl = {
115 Arguments2_QueryInterface,
116 Arguments2_AddRef,
117 Arguments2_Release,
118 Arguments2_GetTypeInfoCount,
119 Arguments2_GetTypeInfo,
120 Arguments2_GetIDsOfNames,
121 Arguments2_Invoke,
122 Arguments2_Item,
123 Arguments2_Count,
124 Arguments2_get_length
125 };
126
127 IArguments2 arguments_obj = { &Arguments2Vtbl };