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
| using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Global;
namespace IEPlugin {
[
Guid ("D54C4D88-5C93-49c0-9FE7-2CB076A2FDD1"),
ComVisible (true),
ClassInterface (ClassInterfaceType.None)
]
public class Henk : IInternetProtocol, IInternetProtocolRoot, IClassFactory, IInternetProtocolInfo {
private IInternetProtocol oProtocol;
private IInternetProtocolInfo oProtocolInfo;
[ThreadStatic]
private static Henk oInstance;
[Flags]
private enum CLSCTX {
CLSCTX_INPROC_SERVER = 0x1,
CLSCTX_INPROC_HANDLER = 0x2,
CLSCTX_LOCAL_SERVER = 0x4,
CLSCTX_INPROC_SERVER16 = 0x8,
CLSCTX_REMOTE_SERVER = 0x10,
CLSCTX_INPROC_HANDLER16 = 0x20,
CLSCTX_RESERVED1 = 0x40,
CLSCTX_RESERVED2 = 0x80,
CLSCTX_RESERVED3 = 0x100,
CLSCTX_RESERVED4 = 0x200,
CLSCTX_NO_CODE_DOWNLOAD = 0x400,
CLSCTX_RESERVED5 = 0x800,
CLSCTX_NO_CUSTOM_MARSHAL = 0x1000,
CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000,
CLSCTX_NO_FAILURE_LOG = 0x4000,
CLSCTX_DISABLE_AAA = 0x8000,
CLSCTX_ENABLE_AAA = 0x10000,
CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000,
CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,
CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER
}
[DllImport ("ole32.dll", ExactSpelling = true, PreserveSig = false)]
[return: MarshalAs (UnmanagedType.Interface)]
static extern object CoCreateInstance ([In, MarshalAs (UnmanagedType.LPStruct)] Guid rclsid, [MarshalAs (UnmanagedType.IUnknown)] object pUnkOuter, CLSCTX dwClsContext, [In, MarshalAs (UnmanagedType.LPStruct)] Guid riid);
private Henk () {
try {
Guid CLSID_HttpProtocol = new Guid ("79EAC9E2-BAF9-11CE-8C82-00AA004BA90B");
Guid IID_IInternetProtocol = new Guid ("79eac9e4-baf9-11ce-8c82-00aa004ba90b");
Guid IID_IInternetProtocolRoot = new Guid ("79eac9e4-baf9-11ce-8c82-00aa004ba90b");
Guid IID_IInternetProtocolInfo = new Guid ("79eac9e4-baf9-11ce-8c82-00aa004ba90b");
Object o = CoCreateInstance (CLSID_HttpProtocol, null, CLSCTX.CLSCTX_INPROC_SERVER, IID_IInternetProtocol);
this.oProtocol = (IInternetProtocol)o;
MessageBox.Show (this.oProtocol + "", "1");
o = CoCreateInstance (CLSID_HttpProtocol, null, CLSCTX.CLSCTX_INPROC_SERVER, IID_IInternetProtocolInfo);
MessageBox.Show (o + "", "3");
//Hier gaat het fout: het object kan niet gecast worden naar de IInternetProtocolInfo klasse (omdat het object niet van deze interface overerft).
this.oProtocolInfo = (IInternetProtocolInfo)o;
MessageBox.Show (this.oProtocolInfo + "", "4");
} catch (Exception e) {
MessageBox.Show (e.ToString (), "ERROR");
new MM_EventWriter (ref e);
}
}
public static Henk Instance {
get {
if (oInstance == null) {
oInstance = new Henk ();
}
return oInstance;
}
}
#region IInternetProtocolMethods
public void Start (string szURL, IInternetProtocolSink Sink, IInternetBindInfo pOIBindInfo, uint grfPI, uint dwReserved) {
this.oProtocol.Start (szURL, Sink, pOIBindInfo, grfPI, dwReserved);
}
public void Continue (ref _tagPROTOCOLDATA pProtocolData) {
this.oProtocol.Continue (ref pProtocolData);
}
public void Abort (int hrReason, uint dwOptions) {
this.oProtocol.Abort (hrReason, dwOptions);
}
public void Terminate (uint dwOptions) {
this.oProtocol.Terminate (dwOptions);
}
public void Suspend () {
this.oProtocol.Suspend ();
}
public void Resume () {
this.oProtocol.Resume ();
}
public uint Read (IntPtr pv, uint cb, out uint pcbRead) {
return this.oProtocol.Read (pv, cb, out pcbRead);
}
public void Seek (_LARGE_INTEGER dlibMove, uint dwOrigin, out _ULARGE_INTEGER plibNewPosition) {
this.oProtocol.Seek (dlibMove, dwOrigin, out plibNewPosition);
}
public void LockRequest (uint dwOptions) {
this.oProtocol.LockRequest (dwOptions);
}
public void UnlockRequest () {
this.oProtocol.UnlockRequest ();
}
#endregion
#region IClassFactoryMethods
public void CreateInstance (IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject) {
System.Windows.Forms.MessageBox.Show ("CreateInstance", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, System.Windows.Forms.MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.ServiceNotification);
ppvObject = IntPtr.Zero;
if (pUnkOuter != IntPtr.Zero) {
Marshal.ThrowExceptionForHR (CLASS_E_NOAGGREGATION);
}
if (riid == IID_IInternetProtocolInfo || riid == IID_IUnknown) {
MM_Main oMain = new MM_Main ();
ppvObject = Marshal.GetComInterfaceForObject (oMain, typeof (IInternetProtocol));
} else {
Marshal.ThrowExceptionForHR (E_NOINTERFACE);
}
}
private const int CLASS_E_NOAGGREGATION = unchecked ((int)
0x80040110);
private const int E_NOINTERFACE = unchecked ((int)0x80004002);
private readonly Guid IID_IInternetProtocol = new
Guid ("{79EAC9E4-BAF9-11CE-8C82-00AA004BA90B}");
private readonly Guid IID_IInternetProtocolInfo = new
Guid ("{79EAC9EC-BAF9-11CE-8C82-00AA004BA90B}");
private readonly Guid IID_IUnknown = new
Guid ("{00000000-0000-0000-C000-000000000046}");
public void LockServer (bool fLock) {
throw new NotImplementedException ();
}
#endregion
#region IInternetProtocolInfoMethods
public uint ParseUrl (string pwzUrl, PARSEACTION ParseAction, uint dwParseFlags, IntPtr pwzResult, uint cchResult, out uint pcchResult, uint dwReserved) {
//Deze functie zou als eerste aangeroepen moeten worden, maar de messagebox wordt niet getoond.
MessageBox.Show ("ParseUrl", "ParseUrl", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
pcchResult = 0;
return HRESULT.INET_E_DEFAULT_ACTION;
}
public uint CombineUrl (string pwzBaseUrl, string pwzRelativeUrl, uint dwCombineFlags, IntPtr pwzResult, uint cchResult, out uint pcchResult, uint dwReserved) {
MessageBox.Show ("CombineUrl", "CombineUrl", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
pcchResult = 0;
return HRESULT.S_OK;
}
public uint CompareUrl (string pwzUrl1, string pwzUrl2, uint dwCompareFlags) {
MessageBox.Show ("CompareUrl", "CompareUrl", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
return (UInt32)pwzUrl1.CompareTo (pwzUrl2);
}
public uint QueryInfo (string pwzUrl, QUERYOPTION OueryOption, uint dwQueryFlags, IntPtr pBuffer, uint cbBuffer, ref uint pcbBuf, uint dwReserved) {
MessageBox.Show ("QueryInfo", "QueryInfo", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
return HRESULT.INET_E_DEFAULT_ACTION;
}
#endregion
}
} |