97
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
98
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
97
|
12 *******************************************************************************/
|
|
13 module dwt.ole.win32.OLE;
|
|
14
|
|
15 import dwt.dwthelper.File;
|
|
16
|
|
17 import dwt.DWT;
|
|
18 import dwt.DWTError;
|
|
19 import dwt.DWTException;
|
|
20 import dwt.internal.ole.win32.COM;
|
|
21 import dwt.internal.win32.OS;
|
|
22
|
|
23 import dwt.dwthelper.utils;
|
|
24 import tango.util.Convert;
|
|
25 /**
|
|
26 *
|
|
27 * OLE contains all the constants used to create an ActiveX Control or an OLE Document.
|
|
28 *
|
|
29 * <p>Definitions for these constants can be found in MSDN.
|
|
30 *
|
|
31 */
|
|
32 public class OLE : DWT {
|
|
33
|
|
34 public static const int S_FALSE = 1; // Used for functions that semantically return a bool FALSE result to indicate that the function succeeded.
|
|
35 public static const int S_OK = 0; // Function succeeded.
|
|
36 public static const int E_FAIL = -2147467259; // Unspecified failure.
|
|
37 public static const int E_INVALIDARG = -2147024809; // Invalid argument
|
|
38 public static const int E_NOINTERFACE = -2147467262; // QueryInterface did not recognize the requested interface.
|
|
39 public static const int E_NOTIMPL = -2147467263; // Not implemented
|
|
40
|
|
41 public static const char[] IID_IUNKNOWN = "{00000000-0000-0000-C000-000000000046}"; //$NON-NLS-1$
|
|
42 public static const char[] IID_IDISPATCH = "{00020400-0000-0000-C000-000000000046}"; //$NON-NLS-1$
|
|
43
|
|
44 // Verbs that can be invoked on this client
|
|
45 public static const int OLEIVERB_DISCARDUNDOSTATE = -6; // close the OLE object and discard the undo state
|
|
46 public static const int OLEIVERB_HIDE = -3; // hide the OLE object
|
|
47 public static const int OLEIVERB_INPLACEACTIVATE = -5; // open the OLE for editing in-place
|
|
48 public static const int OLEIVERB_OPEN = -2; // open the OLE object for editing in a separate window
|
|
49 public static const int OLEIVERB_PRIMARY = 0; // opens the OLE object for editing
|
|
50 public static const int OLEIVERB_PROPERTIES = -7; // request the OLE object properties dialog
|
|
51 public static const int OLEIVERB_SHOW = -1; // show the OLE object
|
|
52 public static const int OLEIVERB_UIACTIVATE = -4; // activate the UI for the OLE object
|
|
53
|
|
54 public static const int PROPERTY_CHANGING = 0;
|
|
55 public static const int PROPERTY_CHANGED = 1;
|
|
56
|
|
57 /**
|
|
58 * Error code for OleError - No specific error information available
|
|
59 */
|
|
60 public static const int HRESULT_UNSPECIFIED = 0;
|
|
61 /**
|
|
62 * Error code for OleError - Failed to create file
|
|
63 */
|
|
64 public static const int ERROR_CANNOT_CREATE_FILE = 1000;
|
|
65 /**
|
|
66 * Error code for OleError - Failed to create Ole Client
|
|
67 */
|
|
68 public static const int ERROR_CANNOT_CREATE_OBJECT = 1001;
|
|
69 /**
|
|
70 * Error code for OleError - File does not exist, is not accessible to user or does not have the correct format
|
|
71 */
|
|
72 public static const int ERROR_CANNOT_OPEN_FILE = 1002;
|
|
73 /**
|
|
74 * Error code for OleError - Failed to find requested interface on OLE Object
|
|
75 */
|
|
76 public static const int ERROR_INTERFACE_NOT_FOUND = 1003;
|
|
77 /**
|
|
78 * Error code for OleError - Class ID not found in registry
|
|
79 */
|
|
80 public static const int ERROR_INVALID_CLASSID = 1004;
|
|
81 /**
|
|
82 * Error code for OleError - Failed to get the class factory for the specified classID
|
|
83 */
|
|
84 public static const int ERROR_CANNOT_ACCESS_CLASSFACTORY = 1005;
|
|
85 /**
|
|
86 * Error code for OleError - Failed to create Licensed instance
|
|
87 */
|
|
88 public static const int ERROR_CANNOT_CREATE_LICENSED_OBJECT = 1006;
|
|
89 /**
|
|
90 * Error code for OleError - Out of Memory
|
|
91 */
|
|
92 public static const int ERROR_OUT_OF_MEMORY = 1007;
|
|
93 /**
|
|
94 * Error code for OleError - Failed to change Variant type
|
|
95 */
|
|
96 public static const int ERROR_CANNOT_CHANGE_VARIANT_TYPE = 1010;
|
|
97 /**
|
|
98 * Error code for OleError - Invalid address received for Ole Interface
|
|
99 */
|
|
100 public static const int ERROR_INVALID_INTERFACE_ADDRESS = 1011;
|
|
101 /**
|
|
102 * Error code for OleError - Unable to find Application
|
|
103 */
|
|
104 public static const int ERROR_APPLICATION_NOT_FOUND = 1013;
|
|
105 /**
|
|
106 * Error code for OleError - Action can not be performed
|
|
107 */
|
|
108 public static const int ERROR_ACTION_NOT_PERFORMED = 1014;
|
|
109
|
|
110 public static const int OLECMDF_SUPPORTED = 1;
|
|
111 public static const int OLECMDF_ENABLED = 2;
|
|
112 public static const int OLECMDF_LATCHED = 4;
|
|
113 public static const int OLECMDF_NINCHED = 8;
|
|
114
|
|
115 public static const int OLECMDTEXTF_NONE = 0;
|
|
116 public static const int OLECMDTEXTF_NAME = 1;
|
|
117 public static const int OLECMDTEXTF_STATUS = 2;
|
|
118
|
|
119 public static const int OLECMDEXECOPT_DODEFAULT = 0;
|
|
120 public static const int OLECMDEXECOPT_PROMPTUSER = 1;
|
|
121 public static const int OLECMDEXECOPT_DONTPROMPTUSER = 2;
|
|
122 public static const int OLECMDEXECOPT_SHOWHELP = 3;
|
|
123
|
|
124 public static const int OLECMDID_OPEN = 1;
|
|
125 public static const int OLECMDID_NEW = 2;
|
|
126 public static const int OLECMDID_SAVE = 3;
|
|
127 public static const int OLECMDID_SAVEAS = 4;
|
|
128 public static const int OLECMDID_SAVECOPYAS = 5;
|
|
129 public static const int OLECMDID_PRINT = 6;
|
|
130 public static const int OLECMDID_PRINTPREVIEW = 7;
|
|
131 public static const int OLECMDID_PAGESETUP = 8;
|
|
132 public static const int OLECMDID_SPELL = 9;
|
|
133 public static const int OLECMDID_PROPERTIES = 10;
|
|
134 public static const int OLECMDID_CUT = 11;
|
|
135 public static const int OLECMDID_COPY = 12;
|
|
136 public static const int OLECMDID_PASTE = 13;
|
|
137 public static const int OLECMDID_PASTESPECIAL = 14;
|
|
138 public static const int OLECMDID_UNDO = 15;
|
|
139 public static const int OLECMDID_REDO = 16;
|
|
140 public static const int OLECMDID_SELECTALL = 17;
|
|
141 public static const int OLECMDID_CLEARSELECTION = 18;
|
|
142 public static const int OLECMDID_ZOOM = 19;
|
|
143 public static const int OLECMDID_GETZOOMRANGE = 20;
|
|
144 public static const int OLECMDID_UPDATECOMMANDS = 21;
|
|
145 public static const int OLECMDID_REFRESH = 22;
|
|
146 public static const int OLECMDID_STOP = 23;
|
|
147 public static const int OLECMDID_HIDETOOLBARS = 24;
|
|
148 public static const int OLECMDID_SETPROGRESSMAX = 25;
|
|
149 public static const int OLECMDID_SETPROGRESSPOS = 26;
|
|
150 public static const int OLECMDID_SETPROGRESSTEXT = 27;
|
|
151 public static const int OLECMDID_SETTITLE = 28;
|
|
152 public static const int OLECMDID_SETDOWNLOADSTATE = 29;
|
|
153 public static const int OLECMDID_STOPDOWNLOAD = 30;
|
|
154
|
|
155 /* Ole Property Description flags */
|
|
156 public static int VARFLAG_FREADONLY = 0x1;
|
|
157 public static int VARFLAG_FSOURCE = 0x2;
|
|
158 public static int VARFLAG_FBINDABLE = 0x4;
|
|
159 public static int VARFLAG_FREQUESTEDIT = 0x8;
|
|
160 public static int VARFLAG_FDISPLAYBIND = 0x10;
|
|
161 public static int VARFLAG_FDEFAULTBIND = 0x20;
|
|
162 public static int VARFLAG_FHIDDEN = 0x40;
|
|
163 public static int VARFLAG_FRESTRICTED = 0x80;
|
|
164 public static int VARFLAG_FDEFAULTCOLLELEM = 0x100;
|
|
165 public static int VARFLAG_FUIDEFAULT = 0x200;
|
|
166 public static int VARFLAG_FNONBROWSABLE = 0x400;
|
|
167 public static int VARFLAG_FREPLACEABLE = 0x800;
|
|
168 public static int VARFLAG_FIMMEDIATEBIND = 0x1000;
|
|
169
|
|
170 /* Ole Property Description kind */
|
|
171 public static int VAR_PERINSTANCE = 0;
|
|
172 public static int VAR_STATIC = 1;
|
|
173 public static int VAR_CONST = 2;
|
|
174 public static int VAR_DISPATCH = 3;
|
|
175
|
|
176 /* Ole Parameter Description flags */
|
|
177 public static short IDLFLAG_NONE = 0;
|
|
178 public static short IDLFLAG_FIN = 1;
|
|
179 public static short IDLFLAG_FOUT = 2;
|
|
180 public static short IDLFLAG_FLCID = 4;
|
|
181 public static short IDLFLAG_FRETVAL = 8;
|
|
182
|
|
183 /* Ole Description types */
|
|
184 public static const short VT_BOOL = 11; // bool; True=-1, False=0.
|
|
185 public static const short VT_BSTR = 8; // Binary String.
|
|
186 public static const short VT_BYREF = 16384; // By reference - must be combined with one of the other VT values
|
|
187 public static const short VT_CY = 6; // Currency.
|
|
188 public static const short VT_DATE = 7; // Date.
|
|
189 public static const short VT_DISPATCH = 9; // IDispatch
|
|
190 public static const short VT_EMPTY = 0; // Not specified.
|
|
191 public static const short VT_ERROR = 10; // Scodes.
|
|
192 public static const short VT_I2 = 2; // 2-byte signed int.
|
|
193 public static const short VT_I4 = 3; // 4-byte signed int.
|
|
194 public static const short VT_NULL = 1; // Null.
|
|
195 public static const short VT_R4 = 4; // 4-byte real.
|
|
196 public static const short VT_R8 = 5; // 8-byte real.
|
|
197 public static const short VT_UI1 = 17; // Unsigned char.
|
|
198 public static const short VT_UI4 = 19; // Unsigned int.
|
|
199 public static const short VT_UNKNOWN = 13; // IUnknown FAR*.
|
|
200 public static const short VT_VARIANT = 12; // VARIANT FAR*.
|
|
201 public static const short VT_PTR = 26;
|
|
202 public static const short VT_USERDEFINED = 29;
|
|
203 public static const short VT_HRESULT = 25;
|
|
204 public static const short VT_DECIMAL = 14;
|
|
205 public static const short VT_I1 = 16;
|
|
206 public static const short VT_UI2 = 18;
|
|
207 public static const short VT_I8 = 20;
|
|
208 public static const short VT_UI8 = 21;
|
|
209 public static const short VT_INT = 22;
|
|
210 public static const short VT_UINT = 23;
|
|
211 public static const short VT_VOID = 24;
|
|
212 public static const short VT_SAFEARRAY = 27;
|
|
213 public static const short VT_CARRAY = 28;
|
|
214 public static const short VT_LPSTR = 30;
|
|
215 public static const short VT_LPWSTR = 31;
|
|
216 public static const short VT_RECORD = 36;
|
|
217 public static const short VT_FILETIME = 64;
|
|
218 public static const short VT_BLOB = 65;
|
|
219 public static const short VT_STREAM = 66;
|
|
220 public static const short VT_STORAGE = 67;
|
|
221 public static const short VT_STREAMED_OBJECT = 68;
|
|
222 public static const short VT_STORED_OBJECT = 69;
|
|
223 public static const short VT_BLOB_OBJECT = 70;
|
|
224 public static const short VT_CF = 71;
|
|
225 public static const short VT_CLSID = 72;
|
|
226 public static const short VT_VERSIONED_STREAM = 73;
|
|
227 public static const short VT_BSTR_BLOB = 0xfff;
|
|
228 public static const short VT_VECTOR = 0x1000;
|
|
229 public static const short VT_ARRAY = 0x2000;
|
|
230
|
|
231 /* Ole Function Description Invoke Kind values */
|
|
232 public static const int INVOKE_FUNC = 1;
|
|
233 public static const int INVOKE_PROPERTYGET = 2;
|
|
234 public static const int INVOKE_PROPERTYPUT = 4;
|
|
235 public static const int INVOKE_PROPERTYPUTREF = 8;
|
|
236
|
|
237 /* Ole Function Description function kind */
|
|
238 public static const int FUNC_VIRTUAL = 0;
|
|
239 public static const int FUNC_PUREVIRTUAL = 1;
|
|
240 public static const int FUNC_NONVIRTUAL = 2;
|
|
241 public static const int FUNC_STATIC = 3;
|
|
242 public static const int FUNC_DISPATCH = 4;
|
|
243
|
|
244 /* Ole Function Description function flags */
|
|
245 public static const short FUNCFLAG_FRESTRICTED = 1;
|
|
246 public static const short FUNCFLAG_FSOURCE = 0x2;
|
|
247 public static const short FUNCFLAG_FBINDABLE = 0x4;
|
|
248 public static const short FUNCFLAG_FREQUESTEDIT = 0x8;
|
|
249 public static const short FUNCFLAG_FDISPLAYBIND = 0x10;
|
|
250 public static const short FUNCFLAG_FDEFAULTBIND = 0x20;
|
|
251 public static const short FUNCFLAG_FHIDDEN = 0x40;
|
|
252 public static const short FUNCFLAG_FUSESGETLASTERROR = 0x80;
|
|
253 public static const short FUNCFLAG_FDEFAULTCOLLELEM = 0x100;
|
|
254 public static const short FUNCFLAG_FUIDEFAULT = 0x200;
|
|
255 public static const short FUNCFLAG_FNONBROWSABLE = 0x400;
|
|
256 public static const short FUNCFLAG_FREPLACEABLE = 0x800;
|
|
257 public static const short FUNCFLAG_FIMMEDIATEBIND = 0x1000;
|
|
258
|
|
259 /* Ole Function Description calling convention */
|
|
260 public static const int CC_FASTCALL = 0;
|
|
261 public static const int CC_CDECL = 1;
|
|
262 public static const int CC_MSCPASCAL = 2;
|
|
263 public static const int CC_PASCAL = 2;
|
|
264 public static const int CC_MACPASCAL = 3;
|
|
265 public static const int CC_STDCALL = 4;
|
|
266 public static const int CC_FPFASTCALL = 5;
|
|
267 public static const int CC_SYSCALL = 6;
|
|
268 public static const int CC_MPWCDECL = 7;
|
|
269 public static const int CC_MPWPASCAL = 8;
|
|
270 public static const int CC_MAX = 9;
|
|
271
|
|
272 static const char[] ERROR_NOT_IMPLEMENTED_MSG = "Required functionality not currently supported.";//$NON-NLS-1$
|
|
273 static const char[] ERROR_CANNOT_CREATE_FILE_MSG = "Failed to create file.";//$NON-NLS-1$
|
|
274 static const char[] ERROR_CANNOT_CREATE_OBJECT_MSG = "Failed to create Ole Client.";//$NON-NLS-1$
|
|
275 static const char[] ERROR_CANNOT_OPEN_FILE_MSG = "File does not exist, is not accessible to user or does not have the correct format.";//$NON-NLS-1$
|
|
276 static const char[] ERROR_INTERFACE_NOT_FOUND_MSG = "Failed to find requested interface on OLE Object.";//$NON-NLS-1$
|
|
277 static const char[] ERROR_INVALID_CLASSID_MSG = "Class ID not found in registry";//$NON-NLS-1$
|
|
278 static const char[] ERROR_CANNOT_ACCESS_CLASSFACTORY_MSG = "Failed to get the class factory for the specified classID";//$NON-NLS-1$
|
|
279 static const char[] ERROR_CANNOT_CREATE_LICENSED_OBJECT_MSG = "Failed to create Licensed instance";//$NON-NLS-1$
|
|
280 static const char[] ERROR_OUT_OF_MEMORY_MSG = "Out of Memory";//$NON-NLS-1$
|
|
281 static const char[] ERROR_CANNOT_CHANGE_VARIANT_TYPE_MSG = "Failed to change Variant type";//$NON-NLS-1$
|
|
282 static const char[] ERROR_INVALID_INTERFACE_ADDRESS_MSG = "Invalid address received for Ole Interface.";//$NON-NLS-1$
|
|
283 static const char[] ERROR_APPLICATION_NOT_FOUND_MSG = "Unable to find Application.";//$NON-NLS-1$
|
|
284 static const char[] ERROR_ACTION_NOT_PERFORMED_MSG = "Action can not be performed.";//$NON-NLS-1$
|
|
285
|
|
286
|
98
|
287 public static void error (char[] file, long line, int code) {
|
|
288 error (code, 0);
|
|
289 }
|
97
|
290 public static void error (int code) {
|
|
291 error (code, 0);
|
|
292 }
|
98
|
293 public static void error (char[] file, long line, int code, int hresult) {
|
|
294 error (code, hresult);
|
|
295 }
|
97
|
296 public static void error (int code, int hresult) {
|
|
297
|
|
298 switch (code) {
|
|
299 /* Illegal Arguments (non-fatal) */
|
|
300 case ERROR_INVALID_INTERFACE_ADDRESS :{
|
|
301 throw new IllegalArgumentException (ERROR_INVALID_INTERFACE_ADDRESS_MSG);
|
|
302 }
|
|
303
|
|
304 /* DWT Errors (non-fatal) */
|
|
305 case ERROR_CANNOT_CREATE_FILE : {
|
|
306 char[] msg = ERROR_CANNOT_CREATE_FILE_MSG;
|
|
307 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
308 throw new DWTException (code, msg);
|
|
309 }
|
|
310 case ERROR_CANNOT_CREATE_OBJECT : {
|
|
311 char[] msg = ERROR_CANNOT_CREATE_OBJECT_MSG;
|
|
312 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
313 throw new DWTException (code, msg);//$NON-NLS-1$
|
|
314 }
|
|
315 case ERROR_CANNOT_OPEN_FILE : {
|
|
316 char[] msg = ERROR_CANNOT_OPEN_FILE_MSG;
|
|
317 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
318 throw new DWTException (code, msg);
|
|
319 }
|
|
320 case ERROR_INTERFACE_NOT_FOUND : {
|
|
321 char[] msg = ERROR_INTERFACE_NOT_FOUND_MSG;
|
|
322 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
323 throw new DWTException (code, msg);
|
|
324 }
|
|
325 case ERROR_INVALID_CLASSID : {
|
|
326 char[] msg = ERROR_INVALID_CLASSID_MSG;
|
|
327 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
328 throw new DWTException (code, msg);
|
|
329 }
|
|
330 case ERROR_CANNOT_ACCESS_CLASSFACTORY : {
|
|
331 char[] msg = ERROR_CANNOT_ACCESS_CLASSFACTORY_MSG;
|
|
332 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
333 throw new DWTException (code, msg);
|
|
334 }
|
|
335 case ERROR_CANNOT_CREATE_LICENSED_OBJECT : {
|
|
336 char[] msg = ERROR_CANNOT_CREATE_LICENSED_OBJECT_MSG;
|
|
337 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
338 throw new DWTException (code, msg);
|
|
339 }
|
|
340 case ERROR_CANNOT_CHANGE_VARIANT_TYPE : {
|
|
341 char[] msg = ERROR_CANNOT_CHANGE_VARIANT_TYPE_MSG;
|
|
342 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
343 throw new DWTException (code, msg);
|
|
344 }
|
|
345 case ERROR_APPLICATION_NOT_FOUND : {
|
|
346 char[] msg = ERROR_APPLICATION_NOT_FOUND_MSG;
|
|
347 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
348 throw new DWTException (code, msg);
|
|
349 }
|
|
350 case ERROR_ACTION_NOT_PERFORMED : {
|
|
351 char[] msg = ERROR_ACTION_NOT_PERFORMED_MSG;
|
|
352 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult);//$NON-NLS-1$
|
|
353 throw new DWTException (code, msg);
|
|
354 }
|
|
355
|
|
356 /* OS Failure/Limit (fatal, may occur only on some platforms) */
|
|
357 case ERROR_OUT_OF_MEMORY : {
|
|
358 char[] msg = ERROR_ACTION_NOT_PERFORMED_MSG;
|
|
359 if (hresult !is 0) msg ~= " result = "~to!(char[])(hresult); //$NON-NLS-1$
|
|
360 throw new DWTError (code, msg);
|
|
361 }
|
|
362 }
|
|
363
|
|
364 /* Unknown/Undefined Error */
|
|
365 DWT.error(code);
|
|
366 }
|
|
367
|
|
368 /*
|
|
369 * Finds the OLE program id that is associated with an extension.
|
|
370 * The extension may or may not begin with a '.'. On platforms
|
|
371 * that do not support OLE, an empty string is returned.
|
|
372 *
|
|
373 * @param extension the program extension
|
|
374 * @return a string that is the OLE program id or an empty string
|
|
375 *
|
|
376 * @exception IllegalArgumentException <ul>
|
|
377 * <li>ERROR_NULL_ARGUMENT when extension is null</li>
|
|
378 * </ul>
|
|
379 */
|
|
380 public static char[] findProgramID (char[] extension) {
|
|
381 if (extension is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
382 if (extension.length is 0) return ""; //$NON-NLS-1$
|
|
383
|
|
384 if (extension.charAt (0) !is '.') extension = "." ~ extension; //$NON-NLS-1$
|
|
385
|
|
386 /* Use the character encoding for the default locale */
|
|
387 TCHAR[] extensionKey = StrToTCHARs(0, extension, true);
|
|
388 char[] result = getKeyValue(extensionKey);
|
|
389 if (result !is null) {
|
|
390 // look for "<programID>\NotInsertable"
|
|
391 TCHAR[] notInsertableKey = StrToTCHARs(0, result~"\\NotInsertable", true); //$NON-NLS-1$
|
|
392 if (getKeyExists(notInsertableKey)) return ""; //$NON-NLS-1$
|
|
393 // look for "<programID>\Insertable"
|
|
394 TCHAR[] insertableKey = StrToTCHARs(0, result~"\\Insertable", true); //$NON-NLS-1$
|
|
395 if (getKeyExists(insertableKey)) return result;
|
|
396 // look for "<programID>\protocol\StdFileEditing\server"
|
|
397 TCHAR[] serverKey = StrToTCHARs(0, result~"\\protocol\\StdFileEditing\\server", true); //$NON-NLS-1$
|
|
398 if (getKeyExists(serverKey)) return result;
|
|
399 }
|
|
400
|
|
401 return ""; //$NON-NLS-1$
|
|
402 }
|
|
403 static char[] getKeyValue (TCHAR[] key) {
|
|
404 void* [1] phkResult;
|
|
405 if (OS.RegOpenKeyEx (cast(void*)OS.HKEY_CLASSES_ROOT, key.ptr, 0, OS.KEY_READ, phkResult.ptr) !is 0) {
|
|
406 return null;
|
|
407 }
|
|
408 char[] result = null;
|
|
409 uint [1] lpcbData;
|
|
410 if (OS.RegQueryValueEx (phkResult [0], null, null, null, null, lpcbData.ptr) is 0) {
|
|
411 int length_ = lpcbData [0] / TCHAR.sizeof;
|
|
412 if (length_ is 0) {
|
|
413 result = "";
|
|
414 } else {
|
|
415 /* Use the character encoding for the default locale */
|
|
416 TCHAR[] lpData = NewTCHARs (0, length_);
|
|
417 if (OS.RegQueryValueEx (phkResult [0], null, null, null, cast(ubyte*)lpData.ptr, lpcbData.ptr) is 0) {
|
|
418 length_ = Math.max(0, lpData.length - 1);
|
|
419 result = TCHARsToStr( lpData[ 0 .. length_ ] );
|
|
420 }
|
|
421 }
|
|
422 }
|
|
423 if (phkResult [0] !is null) OS.RegCloseKey (phkResult [0]);
|
|
424 return result;
|
|
425 }
|
|
426 private static bool getKeyExists (TCHAR[] key) {
|
|
427 void* [1] phkResult;
|
|
428 if (OS.RegOpenKeyEx (cast(void*)OS.HKEY_CLASSES_ROOT, key.ptr, 0, OS.KEY_READ, phkResult.ptr) !is 0) {
|
|
429 return false;
|
|
430 }
|
|
431 if (phkResult [0] !is null) OS.RegCloseKey (phkResult [0]);
|
|
432 return true;
|
|
433 }
|
|
434 /**
|
|
435 * Returns true if the specified file has an OLE Storage format.
|
|
436 *
|
|
437 * Note all empty files (regardless of extension) will return false.
|
|
438 *
|
|
439 * @param file the file to be checked
|
|
440 *
|
|
441 * @return true if this file has an OLE Storage format
|
|
442 */
|
|
443 public static bool isOleFile(File file) {
|
|
444 if (file is null || !file.exists() || file.isDirectory())
|
|
445 return false;
|
|
446
|
|
447 return (COM.StgIsStorageFile( StrToTCHARz(file.getAbsolutePath()~"\0")) is COM.S_OK);
|
|
448 }
|
|
449
|
|
450 }
|