1
1
using System ;
2
+ using System . Runtime . InteropServices ;
3
+ using System . Runtime . InteropServices . ComTypes ;
2
4
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
3
5
4
6
namespace Rubberduck . VBEditor . SafeComWrappers . Office . Core . Abstract
@@ -7,4 +9,66 @@ public interface IControl : ISafeComWrapper, IEquatable<IControl>
7
9
{
8
10
string Name { get ; set ; }
9
11
}
12
+
13
+ public static class ControlExtensions
14
+ {
15
+ public static string TypeName ( this IControl control )
16
+ {
17
+ try
18
+ {
19
+ var dispatch = control . Target as IDispatch ;
20
+ if ( dispatch == null )
21
+ {
22
+ return "Control" ;
23
+ }
24
+ ITypeInfo info ;
25
+ dispatch . GetTypeInfo ( 0 , 0 , out info ) ;
26
+ string name ;
27
+ string docs ;
28
+ int context ;
29
+ string help ;
30
+ info . GetDocumentation ( - 1 , out name , out docs , out context , out help ) ;
31
+ return name ;
32
+ }
33
+ catch
34
+ {
35
+ return "Control" ;
36
+ }
37
+ }
38
+
39
+ [ ComImport ]
40
+ [ Guid ( "00020400-0000-0000-C000-000000000046" ) ]
41
+ [ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
42
+ interface IDispatch
43
+ {
44
+ [ PreserveSig ]
45
+ int GetTypeInfoCount ( out int Count ) ;
46
+
47
+ [ PreserveSig ]
48
+ int GetTypeInfo (
49
+ [ MarshalAs ( UnmanagedType . U4 ) ] int iTInfo ,
50
+ [ MarshalAs ( UnmanagedType . U4 ) ] int lcid ,
51
+ out ITypeInfo typeInfo ) ;
52
+
53
+ [ PreserveSig ]
54
+ int GetIDsOfNames (
55
+ ref Guid riid ,
56
+ [ MarshalAs ( UnmanagedType . LPArray , ArraySubType = UnmanagedType . LPWStr ) ]
57
+ string [ ] rgsNames ,
58
+ int cNames ,
59
+ int lcid ,
60
+ [ MarshalAs ( UnmanagedType . LPArray ) ] int [ ] rgDispId ) ;
61
+
62
+ [ PreserveSig ]
63
+ int Invoke (
64
+ int dispIdMember ,
65
+ ref Guid riid ,
66
+ uint lcid ,
67
+ ushort wFlags ,
68
+ ref System . Runtime . InteropServices . ComTypes . DISPPARAMS pDispParams ,
69
+ out object pVarResult ,
70
+ ref System . Runtime . InteropServices . ComTypes . EXCEPINFO pExcepInfo ,
71
+ IntPtr [ ] pArgErr ) ;
72
+ }
73
+ }
10
74
}
0 commit comments