1 11 package org.eclipse.swt.ole.win32; 12 13 import org.eclipse.swt.*; 14 import java.io.File ; 15 import org.eclipse.swt.internal.ole.win32.COM; 16 import org.eclipse.swt.internal.win32.OS; 17 import org.eclipse.swt.internal.win32.TCHAR; 18 19 20 27 public class OLE extends SWT { 28 29 public static final int S_FALSE = 1; public static final int S_OK = 0; public static final int E_FAIL = -2147467259; public static final int E_INVALIDARG = -2147024809; public static final int E_NOINTERFACE = -2147467262; public static final int E_NOTIMPL = -2147467263; 36 public static final String IID_IUNKNOWN = "{00000000-0000-0000-C000-000000000046}"; public static final String IID_IDISPATCH = "{00020400-0000-0000-C000-000000000046}"; 39 public static final int OLEIVERB_DISCARDUNDOSTATE = -6; public static final int OLEIVERB_HIDE = -3; public static final int OLEIVERB_INPLACEACTIVATE = -5; public static final int OLEIVERB_OPEN = -2; public static final int OLEIVERB_PRIMARY = 0; public static final int OLEIVERB_PROPERTIES = -7; public static final int OLEIVERB_SHOW = -1; public static final int OLEIVERB_UIACTIVATE = -4; 49 public static final int PROPERTY_CHANGING = 0; 50 public static final int PROPERTY_CHANGED = 1; 51 52 55 public static final int HRESULT_UNSPECIFIED = 0; 56 59 public static final int ERROR_CANNOT_CREATE_FILE = 1000; 60 63 public static final int ERROR_CANNOT_CREATE_OBJECT = 1001; 64 67 public static final int ERROR_CANNOT_OPEN_FILE = 1002; 68 71 public static final int ERROR_INTERFACE_NOT_FOUND = 1003; 72 75 public static final int ERROR_INVALID_CLASSID = 1004; 76 79 public static final int ERROR_CANNOT_ACCESS_CLASSFACTORY = 1005; 80 83 public static final int ERROR_CANNOT_CREATE_LICENSED_OBJECT = 1006; 84 87 public static final int ERROR_OUT_OF_MEMORY = 1007; 88 91 public static final int ERROR_CANNOT_CHANGE_VARIANT_TYPE = 1010; 92 95 public static final int ERROR_INVALID_INTERFACE_ADDRESS = 1011; 96 99 public static final int ERROR_APPLICATION_NOT_FOUND = 1013; 100 103 public static final int ERROR_ACTION_NOT_PERFORMED = 1014; 104 105 public static final int OLECMDF_SUPPORTED = 1; 106 public static final int OLECMDF_ENABLED = 2; 107 public static final int OLECMDF_LATCHED = 4; 108 public static final int OLECMDF_NINCHED = 8; 109 110 public static final int OLECMDTEXTF_NONE = 0; 111 public static final int OLECMDTEXTF_NAME = 1; 112 public static final int OLECMDTEXTF_STATUS = 2; 113 114 public static final int OLECMDEXECOPT_DODEFAULT = 0; 115 public static final int OLECMDEXECOPT_PROMPTUSER = 1; 116 public static final int OLECMDEXECOPT_DONTPROMPTUSER = 2; 117 public static final int OLECMDEXECOPT_SHOWHELP = 3; 118 119 public static final int OLECMDID_OPEN = 1; 120 public static final int OLECMDID_NEW = 2; 121 public static final int OLECMDID_SAVE = 3; 122 public static final int OLECMDID_SAVEAS = 4; 123 public static final int OLECMDID_SAVECOPYAS = 5; 124 public static final int OLECMDID_PRINT = 6; 125 public static final int OLECMDID_PRINTPREVIEW = 7; 126 public static final int OLECMDID_PAGESETUP = 8; 127 public static final int OLECMDID_SPELL = 9; 128 public static final int OLECMDID_PROPERTIES = 10; 129 public static final int OLECMDID_CUT = 11; 130 public static final int OLECMDID_COPY = 12; 131 public static final int OLECMDID_PASTE = 13; 132 public static final int OLECMDID_PASTESPECIAL = 14; 133 public static final int OLECMDID_UNDO = 15; 134 public static final int OLECMDID_REDO = 16; 135 public static final int OLECMDID_SELECTALL = 17; 136 public static final int OLECMDID_CLEARSELECTION = 18; 137 public static final int OLECMDID_ZOOM = 19; 138 public static final int OLECMDID_GETZOOMRANGE = 20; 139 public static final int OLECMDID_UPDATECOMMANDS = 21; 140 public static final int OLECMDID_REFRESH = 22; 141 public static final int OLECMDID_STOP = 23; 142 public static final int OLECMDID_HIDETOOLBARS = 24; 143 public static final int OLECMDID_SETPROGRESSMAX = 25; 144 public static final int OLECMDID_SETPROGRESSPOS = 26; 145 public static final int OLECMDID_SETPROGRESSTEXT = 27; 146 public static final int OLECMDID_SETTITLE = 28; 147 public static final int OLECMDID_SETDOWNLOADSTATE = 29; 148 public static final int OLECMDID_STOPDOWNLOAD = 30; 149 150 151 public static int VARFLAG_FREADONLY = 0x1; 152 public static int VARFLAG_FSOURCE = 0x2; 153 public static int VARFLAG_FBINDABLE = 0x4; 154 public static int VARFLAG_FREQUESTEDIT = 0x8; 155 public static int VARFLAG_FDISPLAYBIND = 0x10; 156 public static int VARFLAG_FDEFAULTBIND = 0x20; 157 public static int VARFLAG_FHIDDEN = 0x40; 158 public static int VARFLAG_FRESTRICTED = 0x80; 159 public static int VARFLAG_FDEFAULTCOLLELEM = 0x100; 160 public static int VARFLAG_FUIDEFAULT = 0x200; 161 public static int VARFLAG_FNONBROWSABLE = 0x400; 162 public static int VARFLAG_FREPLACEABLE = 0x800; 163 public static int VARFLAG_FIMMEDIATEBIND = 0x1000; 164 165 166 public static int VAR_PERINSTANCE = 0; 167 public static int VAR_STATIC = 1; 168 public static int VAR_CONST = 2; 169 public static int VAR_DISPATCH = 3; 170 171 172 public static short IDLFLAG_NONE = 0; 173 public static short IDLFLAG_FIN = 1; 174 public static short IDLFLAG_FOUT = 2; 175 public static short IDLFLAG_FLCID = 4; 176 public static short IDLFLAG_FRETVAL = 8; 177 178 179 public static final short VT_BOOL = 11; public static final short VT_BSTR = 8; public static final short VT_BYREF = 16384; public static final short VT_CY = 6; public static final short VT_DATE = 7; public static final short VT_DISPATCH = 9; public static final short VT_EMPTY = 0; public static final short VT_ERROR = 10; public static final short VT_I2 = 2; public static final short VT_I4 = 3; public static final short VT_NULL = 1; public static final short VT_R4 = 4; public static final short VT_R8 = 5; public static final short VT_UI1 = 17; public static final short VT_UI4 = 19; public static final short VT_UNKNOWN = 13; public static final short VT_VARIANT = 12; public static final short VT_PTR = 26; 197 public static final short VT_USERDEFINED = 29; 198 public static final short VT_HRESULT = 25; 199 public static final short VT_DECIMAL = 14; 200 public static final short VT_I1 = 16; 201 public static final short VT_UI2 = 18; 202 public static final short VT_I8 = 20; 203 public static final short VT_UI8 = 21; 204 public static final short VT_INT = 22; 205 public static final short VT_UINT = 23; 206 public static final short VT_VOID = 24; 207 public static final short VT_SAFEARRAY = 27; 208 public static final short VT_CARRAY = 28; 209 public static final short VT_LPSTR = 30; 210 public static final short VT_LPWSTR = 31; 211 public static final short VT_RECORD = 36; 212 public static final short VT_FILETIME = 64; 213 public static final short VT_BLOB = 65; 214 public static final short VT_STREAM = 66; 215 public static final short VT_STORAGE = 67; 216 public static final short VT_STREAMED_OBJECT = 68; 217 public static final short VT_STORED_OBJECT = 69; 218 public static final short VT_BLOB_OBJECT = 70; 219 public static final short VT_CF = 71; 220 public static final short VT_CLSID = 72; 221 public static final short VT_VERSIONED_STREAM = 73; 222 public static final short VT_BSTR_BLOB = 0xfff; 223 public static final short VT_VECTOR = 0x1000; 224 public static final short VT_ARRAY = 0x2000; 225 226 227 public static final int INVOKE_FUNC = 1; 228 public static final int INVOKE_PROPERTYGET = 2; 229 public static final int INVOKE_PROPERTYPUT = 4; 230 public static final int INVOKE_PROPERTYPUTREF = 8; 231 232 233 public static final int FUNC_VIRTUAL = 0; 234 public static final int FUNC_PUREVIRTUAL = 1; 235 public static final int FUNC_NONVIRTUAL = 2; 236 public static final int FUNC_STATIC = 3; 237 public static final int FUNC_DISPATCH = 4; 238 239 240 public static final short FUNCFLAG_FRESTRICTED = 1; 241 public static final short FUNCFLAG_FSOURCE = 0x2; 242 public static final short FUNCFLAG_FBINDABLE = 0x4; 243 public static final short FUNCFLAG_FREQUESTEDIT = 0x8; 244 public static final short FUNCFLAG_FDISPLAYBIND = 0x10; 245 public static final short FUNCFLAG_FDEFAULTBIND = 0x20; 246 public static final short FUNCFLAG_FHIDDEN = 0x40; 247 public static final short FUNCFLAG_FUSESGETLASTERROR = 0x80; 248 public static final short FUNCFLAG_FDEFAULTCOLLELEM = 0x100; 249 public static final short FUNCFLAG_FUIDEFAULT = 0x200; 250 public static final short FUNCFLAG_FNONBROWSABLE = 0x400; 251 public static final short FUNCFLAG_FREPLACEABLE = 0x800; 252 public static final short FUNCFLAG_FIMMEDIATEBIND = 0x1000; 253 254 255 public static final int CC_FASTCALL = 0; 256 public static final int CC_CDECL = 1; 257 public static final int CC_MSCPASCAL = 2; 258 public static final int CC_PASCAL = 2; 259 public static final int CC_MACPASCAL = 3; 260 public static final int CC_STDCALL = 4; 261 public static final int CC_FPFASTCALL = 5; 262 public static final int CC_SYSCALL = 6; 263 public static final int CC_MPWCDECL = 7; 264 public static final int CC_MPWPASCAL = 8; 265 public static final int CC_MAX = 9; 266 267 static final String ERROR_NOT_IMPLEMENTED_MSG = "Required functionality not currently supported."; static final String ERROR_CANNOT_CREATE_FILE_MSG = "Failed to create file."; static final String ERROR_CANNOT_CREATE_OBJECT_MSG = "Failed to create Ole Client."; static final String ERROR_CANNOT_OPEN_FILE_MSG = "File does not exist, is not accessible to user or does not have the correct format."; static final String ERROR_INTERFACE_NOT_FOUND_MSG = "Failed to find requested interface on OLE Object."; static final String ERROR_INVALID_CLASSID_MSG = "Class ID not found in registry"; static final String ERROR_CANNOT_ACCESS_CLASSFACTORY_MSG = "Failed to get the class factory for the specified classID"; static final String ERROR_CANNOT_CREATE_LICENSED_OBJECT_MSG = "Failed to create Licensed instance"; static final String ERROR_OUT_OF_MEMORY_MSG = "Out of Memory"; static final String ERROR_CANNOT_CHANGE_VARIANT_TYPE_MSG = "Failed to change Variant type"; static final String ERROR_INVALID_INTERFACE_ADDRESS_MSG = "Invalid address received for Ole Interface."; static final String ERROR_APPLICATION_NOT_FOUND_MSG = "Unable to find Application."; static final String ERROR_ACTION_NOT_PERFORMED_MSG = "Action can not be performed."; 281 282 public static void error (int code) { 283 error (code, 0); 284 } 285 public static void error (int code, int hresult) { 286 287 switch (code) { 288 289 case ERROR_INVALID_INTERFACE_ADDRESS :{ 290 throw new IllegalArgumentException (ERROR_INVALID_INTERFACE_ADDRESS_MSG); 291 } 292 293 294 case ERROR_CANNOT_CREATE_FILE : { 295 String msg = ERROR_CANNOT_CREATE_FILE_MSG; 296 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 298 } 299 case ERROR_CANNOT_CREATE_OBJECT : { 300 String msg = ERROR_CANNOT_CREATE_OBJECT_MSG; 301 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); } 304 case ERROR_CANNOT_OPEN_FILE : { 305 String msg = ERROR_CANNOT_OPEN_FILE_MSG; 306 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 308 } 309 case ERROR_INTERFACE_NOT_FOUND : { 310 String msg = ERROR_INTERFACE_NOT_FOUND_MSG; 311 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 313 } 314 case ERROR_INVALID_CLASSID : { 315 String msg = ERROR_INVALID_CLASSID_MSG; 316 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 318 } 319 case ERROR_CANNOT_ACCESS_CLASSFACTORY : { 320 String msg = ERROR_CANNOT_ACCESS_CLASSFACTORY_MSG; 321 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 323 } 324 case ERROR_CANNOT_CREATE_LICENSED_OBJECT : { 325 String msg = ERROR_CANNOT_CREATE_LICENSED_OBJECT_MSG; 326 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 328 } 329 case ERROR_CANNOT_CHANGE_VARIANT_TYPE : { 330 String msg = ERROR_CANNOT_CHANGE_VARIANT_TYPE_MSG; 331 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 333 } 334 case ERROR_APPLICATION_NOT_FOUND : { 335 String msg = ERROR_APPLICATION_NOT_FOUND_MSG; 336 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 338 } 339 case ERROR_ACTION_NOT_PERFORMED : { 340 String msg = ERROR_ACTION_NOT_PERFORMED_MSG; 341 if (hresult != 0) msg += " result = "+hresult; throw new SWTException (code, msg); 343 } 344 345 346 case ERROR_OUT_OF_MEMORY : { 347 String msg = ERROR_ACTION_NOT_PERFORMED_MSG; 348 if (hresult != 0) msg += " result = "+hresult; throw new SWTError (code, msg); 350 } 351 } 352 353 354 SWT.error(code); 355 } 356 357 369 public static String findProgramID (String extension) { 370 if (extension == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 371 if (extension.length () == 0) return ""; 373 if (extension.charAt (0) != '.') extension = "." + extension; 375 376 TCHAR extensionKey = new TCHAR(0, extension, true); 377 String result = getKeyValue(extensionKey); 378 if (result != null) { 379 TCHAR notInsertableKey = new TCHAR(0, result+"\\NotInsertable", true); if (getKeyExists(notInsertableKey)) return ""; TCHAR insertableKey = new TCHAR(0, result+"\\Insertable", true); if (getKeyExists(insertableKey)) return result; 385 TCHAR serverKey = new TCHAR(0, result+"\\protocol\\StdFileEditing\\server", true); if (getKeyExists(serverKey)) return result; 388 } 389 390 return ""; } 392 static String getKeyValue (TCHAR key) { 393 int [] phkResult = new int [1]; 394 if (OS.RegOpenKeyEx (OS.HKEY_CLASSES_ROOT, key, 0, OS.KEY_READ, phkResult) != 0) { 395 return null; 396 } 397 String result = null; 398 int [] lpcbData = new int [1]; 399 if (OS.RegQueryValueEx (phkResult [0], (TCHAR) null, 0, null, (TCHAR) null, lpcbData) == 0) { 400 int length = lpcbData [0] / TCHAR.sizeof; 401 if (length == 0) { 402 result = ""; 403 } else { 404 405 TCHAR lpData = new TCHAR (0, length); 406 if (OS.RegQueryValueEx (phkResult [0], null, 0, null, lpData, lpcbData) == 0) { 407 length = Math.max(0, lpData.length () - 1); 408 result = lpData.toString (0, length); 409 } 410 } 411 } 412 if (phkResult [0] != 0) OS.RegCloseKey (phkResult [0]); 413 return result; 414 } 415 private static boolean getKeyExists (TCHAR key) { 416 int [] phkResult = new int [1]; 417 if (OS.RegOpenKeyEx (OS.HKEY_CLASSES_ROOT, key, 0, OS.KEY_READ, phkResult) != 0) { 418 return false; 419 } 420 if (phkResult [0] != 0) OS.RegCloseKey (phkResult [0]); 421 return true; 422 } 423 432 public static boolean isOleFile(File file) { 433 if (file == null || !file.exists() || file.isDirectory()) 434 return false; 435 436 return (COM.StgIsStorageFile((file.getAbsolutePath()+"\0").toCharArray()) == COM.S_OK); 437 } 438 439 } 440 | Popular Tags |