forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveXScripting.cs
More file actions
405 lines (343 loc) · 10.9 KB
/
ActiveXScripting.cs
File metadata and controls
405 lines (343 loc) · 10.9 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Runtime.InteropServices;
using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO;
namespace Microsoft.ClearScript.Windows
{
#region enums
[Flags]
internal enum ScriptInfoFlags : uint
{
// ReSharper disable InconsistentNaming
None = 0,
IUnknown = 0x00000001,
ITypeInfo = 0x00000002
// ReSharper restore InconsistentNaming
}
[Flags]
internal enum ScriptInterruptFlags : uint
{
None = 0,
Debug = 0x00000001,
RaiseException = 0x00000002
}
[Flags]
internal enum ScriptItemFlags : uint
{
None = 0,
IsVisible = 0x00000002,
IsSource = 0x00000004,
GlobalMembers = 0x00000008,
IsPersistent = 0x00000040,
CodeOnly = 0x00000200,
NoCode = 0x00000400
}
internal enum ScriptState : uint
{
Uninitialized = 0,
Initialized = 5,
Started = 1,
Connected = 2,
Disconnected = 3,
Closed = 4
}
internal enum ScriptThreadState : uint
{
NotInScript = 0,
Running = 1
}
[Flags]
internal enum ScriptTypeLibFlags : uint
{
None = 0,
IsControl = 0x00000010,
IsPersistent = 0x00000040
}
[Flags]
internal enum ScriptTextFlags : uint
{
None = 0,
DelayExecution = 0x00000001,
IsVisible = 0x00000002,
IsExpression = 0x00000020,
IsPersistent = 0x00000040,
HostManagesSource = 0x00000080,
IsXDomain = 0x00000100
}
internal enum ScriptGCType
{
Normal = 0,
Exhaustive = 1
}
internal enum ScriptProp : uint
{
Name = 0x00000000,
MajorVersion = 0x00000001,
MinorVersion = 0x00000002,
BuildNumber = 0x00000003,
DelayedEventSinking = 0x00001000,
CatchException = 0x00001001,
ConversionLCID = 0x00001002,
HostStackRequired = 0x00001003,
Debugger = 0x00001100,
JITDebug = 0x00001101,
GCControlSoftClose = 0x00002000,
IntegerMode = 0x00003000,
StringCompareInstance = 0x00003001,
InvokeVersioning = 0x00004000,
HackFiberSupport = 0x70000000,
HackTridentEventSink = 0x70000001,
AbbreviateGlobalNameResolution = 0x70000002,
HostKeepAlive = 0x70000004
}
internal enum ScriptLanguageVersion
{
Default = 0,
Compatibility = 1,
Standards = 2,
Max = 255
}
#endregion
#region constants
internal static class ScriptThreadID
{
public const uint Current = 0xFFFFFFFF;
public const uint Base = 0xFFFFFFFE;
public const uint All = 0xFFFFFFFD;
}
#endregion
#region interfaces
[ComImport]
[Guid("bb1a2ae1-a4f9-11cf-8f20-00805f2cd064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScript
{
void SetScriptSite(
[In] IActiveScriptSite site
);
void GetScriptSite(
[In] ref Guid iid,
[Out] [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] out object site
);
void SetScriptState(
[In] ScriptState state
);
void GetScriptState(
[Out] out ScriptState state
);
void Close();
void AddNamedItem(
[In] [MarshalAs(UnmanagedType.LPWStr)] string name,
[In] ScriptItemFlags flags
);
void AddTypeLib(
[In] ref Guid libid,
[In] uint major,
[In] uint minor,
[In] ScriptTypeLibFlags flags
);
void GetScriptDispatch(
[In] [MarshalAs(UnmanagedType.LPWStr)] string itemName,
[Out] [MarshalAs(UnmanagedType.IDispatch)] out object dispatch
);
void GetCurrentScriptThreadID(
[Out] out uint scriptThreadID
);
void GetScriptThreadID(
[In] uint win32ThreadID,
[Out] out uint scriptThreadID
);
void GetScriptThreadState(
[In] uint scriptThreadID,
[Out] out ScriptThreadState state
);
void InterruptScriptThread(
[In] uint scriptThreadID,
[In] ref EXCEPINFO excepInfo,
[In] ScriptInterruptFlags flags
);
void Clone(
[Out] [MarshalAs(UnmanagedType.Interface)] out IActiveScript script
);
}
[ComImport]
[Guid("bb1a2ae2-a4f9-11cf-8f20-00805f2cd064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptParse32
{
void InitNew();
void AddScriptlet(
[In] [MarshalAs(UnmanagedType.LPWStr)] string defaultName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string code,
[In] [MarshalAs(UnmanagedType.LPWStr)] string itemName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string subItemName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string eventName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter,
[In] uint sourceContext,
[In] uint startingLineNumber,
[In] ScriptTextFlags flags,
[Out] [MarshalAs(UnmanagedType.BStr)] out string name,
[Out] out EXCEPINFO excepInfo
);
void ParseScriptText(
[In] [MarshalAs(UnmanagedType.LPWStr)] string code,
[In] [MarshalAs(UnmanagedType.LPWStr)] string itemName,
[In] [MarshalAs(UnmanagedType.IUnknown)] object context,
[In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter,
[In] uint sourceContext,
[In] uint startingLineNumber,
[In] ScriptTextFlags flags,
[In] IntPtr pVarResult,
[Out] out EXCEPINFO excepInfo
);
}
[ComImport]
[Guid("c7ef7658-e1ee-480e-97ea-d52cb4d76d17")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptParse64
{
void InitNew();
void AddScriptlet(
[In] [MarshalAs(UnmanagedType.LPWStr)] string defaultName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string code,
[In] [MarshalAs(UnmanagedType.LPWStr)] string itemName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string subItemName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string eventName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter,
[In] ulong sourceContext,
[In] uint startingLineNumber,
[In] ScriptTextFlags flags,
[Out] [MarshalAs(UnmanagedType.BStr)] out string name,
[Out] out EXCEPINFO excepInfo
);
void ParseScriptText(
[In] [MarshalAs(UnmanagedType.LPWStr)] string code,
[In] [MarshalAs(UnmanagedType.LPWStr)] string itemName,
[In] [MarshalAs(UnmanagedType.IUnknown)] object context,
[In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter,
[In] ulong sourceContext,
[In] uint startingLineNumber,
[In] ScriptTextFlags flags,
[In] IntPtr pVarResult,
[Out] out EXCEPINFO excepInfo
);
}
[ComImport]
[Guid("db01a1e3-a42b-11cf-8f20-00805f2cd064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptSite
{
void GetLCID(
[Out] out uint lcid
);
void GetItemInfo(
[In] [MarshalAs(UnmanagedType.LPWStr)] string name,
[In] ScriptInfoFlags mask,
[In] [Out] ref IntPtr pUnkItem,
[In] [Out] ref IntPtr pTypeInfo
);
void GetDocVersionString(
[Out] [MarshalAs(UnmanagedType.BStr)] out string version
);
void OnScriptTerminate(
[In] IntPtr pVarResult,
[In] ref EXCEPINFO excepInfo
);
void OnStateChange(
[In] ScriptState state
);
void OnScriptError(
[In] IActiveScriptError error
);
void OnEnterScript();
void OnLeaveScript();
}
[ComImport]
[Guid("539698a0-cdca-11cf-a5eb-00aa0047a063")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptSiteInterruptPoll
{
[PreserveSig]
uint QueryContinue();
}
[ComImport]
[Guid("d10f6761-83e9-11cf-8f20-00805f2cd064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptSiteWindow
{
void GetWindow(
[Out] out IntPtr hwnd
);
void EnableModeless(
[In] [MarshalAs(UnmanagedType.Bool)] bool enable
);
}
[ComImport]
[Guid("eae1ba61-a4ed-11cf-8f20-00805f2cd064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptError
{
void GetExceptionInfo(
[Out] out EXCEPINFO excepInfo
);
void GetSourcePosition(
[Out] out uint sourceContext,
[Out] out uint lineNumber,
[Out] out int position
);
void GetSourceLineText(
[Out] [MarshalAs(UnmanagedType.BStr)] out string sourceLine
);
}
[ComImport]
[Guid("b21fb2a1-5b8f-4963-8c21-21450f84ed7f")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptError64 // : IActiveScriptError
{
#region IActiveScriptError methods
void GetExceptionInfo(
[Out] out EXCEPINFO excepInfo
);
void GetSourcePosition(
[Out] out uint sourceContext,
[Out] out uint lineNumber,
[Out] out int position
);
void GetSourceLineText(
[Out] [MarshalAs(UnmanagedType.BStr)] out string sourceLine
);
#endregion
void GetSourcePosition64(
[Out] out ulong sourceContext,
[Out] out uint lineNumber,
[Out] out int position
);
}
[ComImport]
[Guid("6aa2c4a0-2b53-11d4-a2a0-00104bd35090")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptGarbageCollector
{
void CollectGarbage(
[In] ScriptGCType type
);
}
[ComImport]
[Guid("4954e0d0-fbc7-11d1-8410-006008c3fbfc")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptProperty
{
void GetProperty(
[In] ScriptProp property,
[In] IntPtr pVarIndex,
[Out] [MarshalAs(UnmanagedType.Struct)] out object value
);
void SetProperty(
[In] ScriptProp property,
[In] IntPtr pVarIndex,
[In] [MarshalAs(UnmanagedType.Struct)] ref object value
);
}
#endregion
}