ext/win32ole/win32ole.c in win32ole-1.8.10 vs ext/win32ole/win32ole.c in win32ole-1.9.0
- old
+ new
@@ -25,11 +25,11 @@
#if defined(__CYGWIN__) || defined(__MINGW32__)
#undef IID_IMultiLanguage2
const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00, 0xC0, 0x4F, 0x8F, 0x5D, 0x9A}};
#endif
-#define WIN32OLE_VERSION "1.8.10"
+#define WIN32OLE_VERSION "1.9.0"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
typedef HWND (WINAPI FNHTMLHELP)(HWND hwndCaller, LPCSTR pszFile,
@@ -1424,13 +1424,14 @@
while ( vt == (VT_BYREF | VT_VARIANT) ) {
pvar = V_VARIANTREF(pvar);
vt = V_VT(pvar);
}
+#define ARG_AS(type, pvar) (V_ISBYREF(pvar) ? *V_##type##REF(pvar) : V_##type(pvar))
if(V_ISARRAY(pvar)) {
VARTYPE vt_base = vt & VT_TYPEMASK;
- SAFEARRAY *psa = V_ISBYREF(pvar) ? *V_ARRAYREF(pvar) : V_ARRAY(pvar);
+ SAFEARRAY *psa = ARG_AS(ARRAY, pvar);
UINT i = 0;
LONG *pid, *plb, *pub;
VARIANT variant;
VALUE val;
UINT dim = 0;
@@ -1493,141 +1494,81 @@
case VT_EMPTY:
break;
case VT_NULL:
break;
case VT_I1:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_I1REF(pvar));
- else
- obj = RB_INT2NUM((long)V_I1(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(I1, pvar));
break;
case VT_UI1:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_UI1REF(pvar));
- else
- obj = RB_INT2NUM((long)V_UI1(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(UI1, pvar));
break;
case VT_I2:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_I2REF(pvar));
- else
- obj = RB_INT2NUM((long)V_I2(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(I2, pvar));
break;
case VT_UI2:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_UI2REF(pvar));
- else
- obj = RB_INT2NUM((long)V_UI2(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(UI2, pvar));
break;
case VT_I4:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_I4REF(pvar));
- else
- obj = RB_INT2NUM((long)V_I4(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(I4, pvar));
break;
case VT_UI4:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_UI4REF(pvar));
- else
- obj = RB_INT2NUM((long)V_UI4(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(UI4, pvar));
break;
case VT_INT:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_INTREF(pvar));
- else
- obj = RB_INT2NUM((long)V_INT(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(INT, pvar));
break;
case VT_UINT:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM((long)*V_UINTREF(pvar));
- else
- obj = RB_INT2NUM((long)V_UINT(pvar));
+ obj = RB_INT2NUM((long)ARG_AS(UINT, pvar));
break;
#if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__CYGWIN__) || defined(__MINGW32__)
case VT_I8:
- if(V_ISBYREF(pvar))
-#if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__CYGWIN__) || defined(__MINGW32__)
-#ifdef V_I8REF
- obj = I8_2_NUM(*V_I8REF(pvar));
-#endif
-#else
- obj = Qnil;
-#endif
- else
- obj = I8_2_NUM(V_I8(pvar));
+ obj = I8_2_NUM(ARG_AS(I8, pvar));
break;
case VT_UI8:
- if(V_ISBYREF(pvar))
-#if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__CYGWIN__) || defined(__MINGW32__)
-#ifdef V_UI8REF
- obj = UI8_2_NUM(*V_UI8REF(pvar));
-#endif
-#else
- obj = Qnil;
-#endif
- else
- obj = UI8_2_NUM(V_UI8(pvar));
+ obj = UI8_2_NUM(ARG_AS(UI8, pvar));
break;
#endif /* (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__CYGWIN__) || defined(__MINGW32__) */
case VT_R4:
- if(V_ISBYREF(pvar))
- obj = rb_float_new(*V_R4REF(pvar));
- else
- obj = rb_float_new(V_R4(pvar));
+ obj = rb_float_new(ARG_AS(R4, pvar));
break;
case VT_R8:
- if(V_ISBYREF(pvar))
- obj = rb_float_new(*V_R8REF(pvar));
- else
- obj = rb_float_new(V_R8(pvar));
+ obj = rb_float_new(ARG_AS(R8, pvar));
break;
case VT_BSTR:
{
BSTR bstr;
- if(V_ISBYREF(pvar))
- bstr = *V_BSTRREF(pvar);
- else
- bstr = V_BSTR(pvar);
+ bstr = ARG_AS(BSTR, pvar);
obj = (SysStringLen(bstr) == 0)
? rb_str_new2("")
: ole_wc2vstr(bstr, FALSE);
break;
}
case VT_ERROR:
- if(V_ISBYREF(pvar))
- obj = RB_INT2NUM(*V_ERRORREF(pvar));
- else
- obj = RB_INT2NUM(V_ERROR(pvar));
+ obj = RB_INT2NUM(ARG_AS(ERROR, pvar));
break;
case VT_BOOL:
- if (V_ISBYREF(pvar))
- obj = (*V_BOOLREF(pvar) ? Qtrue : Qfalse);
- else
- obj = (V_BOOL(pvar) ? Qtrue : Qfalse);
+ obj = (ARG_AS(BOOL, pvar) ? Qtrue : Qfalse);
break;
case VT_DISPATCH:
{
IDispatch *pDispatch;
- if (V_ISBYREF(pvar))
- pDispatch = *V_DISPATCHREF(pvar);
- else
- pDispatch = V_DISPATCH(pvar);
+ pDispatch = ARG_AS(DISPATCH, pvar);
if (pDispatch != NULL ) {
OLE_ADDREF(pDispatch);
obj = create_win32ole_object(cWIN32OLE, pDispatch, 0, 0);
}
@@ -1640,14 +1581,11 @@
IUnknown *punk;
IDispatch *pDispatch;
void *p;
HRESULT hr;
- if (V_ISBYREF(pvar))
- punk = *V_UNKNOWNREF(pvar);
- else
- punk = V_UNKNOWN(pvar);
+ punk = ARG_AS(UNKNOWN, pvar);
if(punk != NULL) {
hr = punk->lpVtbl->QueryInterface(punk, &IID_IDispatch, &p);
if(SUCCEEDED(hr)) {
pDispatch = p;
@@ -1658,14 +1596,11 @@
}
case VT_DATE:
{
DATE date;
- if(V_ISBYREF(pvar))
- date = *V_DATEREF(pvar);
- else
- date = V_DATE(pvar);
+ date = ARG_AS(DATE, pvar);
obj = vtdate2rbtime(date);
break;
}
@@ -1691,10 +1626,11 @@
VariantClear(&variant);
break;
}
}
return obj;
+#undef ARG_AS
}
LONG
reg_open_key(HKEY hkey, const char *name, HKEY *phkey)
{
@@ -1960,11 +1896,11 @@
return create_win32ole_object(self, pDispatch, argc, argv);
}
/*
* call-seq:
- * WIN32OLE.connect( ole ) --> aWIN32OLE
+ * connect(ole) --> aWIN32OLE
*
* Returns running OLE Automation object or WIN32OLE object from moniker.
* 1st argument should be OLE program id or class id or moniker.
*
* WIN32OLE.connect('Excel.Application') # => WIN32OLE object which represents running Excel.
@@ -2017,11 +1953,11 @@
return create_win32ole_object(self, pDispatch, argc, argv);
}
/*
* call-seq:
- * WIN32OLE.const_load( ole, mod = WIN32OLE)
+ * const_load(ole, mod = WIN32OLE)
*
* Defines the constants of OLE Automation server as mod's constants.
* The first argument is WIN32OLE object or type library name.
* If 2nd argument is omitted, the default is WIN32OLE.
* The first letter of Ruby's constant variable name is upper case,
@@ -2122,11 +2058,11 @@
return n;
}
/*
* call-seq:
- * WIN32OLE.ole_reference_count(aWIN32OLE) --> number
+ * ole_reference_count(aWIN32OLE) --> number
*
* Returns reference counter of Dispatch interface of WIN32OLE object.
* You should not use this method because this method
* exists only for debugging WIN32OLE.
*/
@@ -2138,11 +2074,11 @@
return RB_INT2NUM(reference_count(pole));
}
/*
* call-seq:
- * WIN32OLE.ole_free(aWIN32OLE) --> number
+ * ole_free(aWIN32OLE) --> number
*
* Invokes Release method of Dispatch interface of WIN32OLE object.
* You should not use this method because this method
* exists only for debugging WIN32OLE.
* The return value is reference counter of OLE object.
@@ -2182,14 +2118,14 @@
return hwnd;
}
/*
* call-seq:
- * WIN32OLE.ole_show_help(obj [,helpcontext])
+ * ole_show_help(obj [,helpcontext])
*
- * Displays helpfile. The 1st argument specifies WIN32OLE_TYPE
- * object or WIN32OLE_METHOD object or helpfile.
+ * Displays helpfile. The 1st argument specifies WIN32OLE::Type
+ * object or WIN32OLE::Method object or helpfile.
*
* excel = WIN32OLE.new('Excel.Application')
* typeobj = excel.ole_type
* WIN32OLE.ole_show_help(typeobj)
*/
@@ -2213,11 +2149,11 @@
helpcontext = rb_funcall(target, rb_intern("helpcontext"), 0);
} else {
helpfile = target;
}
if (!RB_TYPE_P(helpfile, T_STRING)) {
- rb_raise(rb_eTypeError, "1st parameter must be (String|WIN32OLE_TYPE|WIN32OLE_METHOD)");
+ rb_raise(rb_eTypeError, "1st parameter must be (String|WIN32OLE::Type|WIN32OLE::Method)");
}
hwnd = ole_show_help(helpfile, helpcontext);
if(hwnd == 0) {
rb_raise(rb_eRuntimeError, "failed to open help file `%s'",
StringValuePtr(helpfile));
@@ -2225,11 +2161,11 @@
return Qnil;
}
/*
* call-seq:
- * WIN32OLE.codepage
+ * codepage
*
* Returns current codepage.
* WIN32OLE.codepage # => WIN32OLE::CP_ACP
*/
static VALUE
@@ -2256,11 +2192,11 @@
return g_cp_installed;
}
/*
* call-seq:
- * WIN32OLE.codepage = CP
+ * codepage = CP
*
* Sets current codepage.
* The WIN32OLE.codepage is initialized according to
* Encoding.default_internal.
* If Encoding.default_internal is nil then WIN32OLE.codepage
@@ -2280,11 +2216,11 @@
return Qnil;
}
/*
* call-seq:
- * WIN32OLE.locale -> locale id.
+ * locale -> locale id.
*
* Returns current locale id (lcid). The default locale is
* WIN32OLE::LOCALE_SYSTEM_DEFAULT.
*
* lcid = WIN32OLE.locale
@@ -2314,16 +2250,16 @@
return g_lcid_installed;
}
/*
* call-seq:
- * WIN32OLE.locale = lcid
+ * locale = lcid
*
* Sets current locale id (lcid).
*
* WIN32OLE.locale = 1033 # set locale English(U.S)
- * obj = WIN32OLE_VARIANT.new("$100,000", WIN32OLE::VARIANT::VT_CY)
+ * obj = WIN32OLE::Variant.new("$100,000", WIN32OLE::VARIANT::VT_CY)
*
*/
static VALUE
fole_s_set_locale(VALUE self, VALUE vlcid)
{
@@ -2343,11 +2279,11 @@
return Qnil;
}
/*
* call-seq:
- * WIN32OLE.create_guid
+ * create_guid
*
* Creates GUID.
* WIN32OLE.create_guid # => {1CB530F1-F6B1-404D-BCE6-1959BF91F4A8}
*/
static VALUE
@@ -2391,13 +2327,13 @@
}
/*
* Document-class: WIN32OLE
*
- * <code>WIN32OLE</code> objects represent OLE Automation object in Ruby.
+ * +WIN32OLE+ objects represent OLE Automation object in Ruby.
*
- * By using WIN32OLE, you can access OLE server like VBScript.
+ * By using +WIN32OLE+, you can access OLE server like VBScript.
*
* Here is sample script.
*
* require 'win32ole'
*
@@ -2417,31 +2353,31 @@
* workbook.saved = true;
*
* excel.ActiveWorkbook.Close(0);
* excel.Quit();
*
- * Unfortunately, Win32OLE doesn't support the argument passed by
+ * Unfortunately, +WIN32OLE+ doesn't support the argument passed by
* reference directly.
- * Instead, Win32OLE provides WIN32OLE::ARGV or WIN32OLE_VARIANT object.
+ * Instead, +WIN32OLE+ provides WIN32OLE::ARGV or WIN32OLE::Variant object.
* If you want to get the result value of argument passed by reference,
- * you can use WIN32OLE::ARGV or WIN32OLE_VARIANT.
+ * you can use WIN32OLE::ARGV or WIN32OLE::Variant.
*
* oleobj.method(arg1, arg2, refargv3)
* puts WIN32OLE::ARGV[2] # the value of refargv3 after called oleobj.method
*
* or
*
- * refargv3 = WIN32OLE_VARIANT.new(XXX,
+ * refargv3 = WIN32OLE::Variant.new(XXX,
* WIN32OLE::VARIANT::VT_BYREF|WIN32OLE::VARIANT::VT_XXX)
* oleobj.method(arg1, arg2, refargv3)
* p refargv3.value # the value of refargv3 after called oleobj.method.
*
*/
/*
* call-seq:
- * WIN32OLE.new(server, [host]) -> WIN32OLE object
+ * new(server, [host]) -> WIN32OLE object
* WIN32OLE.new(server, license: 'key') -> WIN32OLE object
*
* Returns a new WIN32OLE object(OLE Automation object).
* The first argument server specifies OLE Automation server.
* The first argument should be CLSID or PROGID.
@@ -2824,11 +2760,11 @@
return obj;
}
/*
* call-seq:
- * WIN32OLE#invoke(method, [arg1,...]) => return value of method.
+ * invoke(method, [arg1,...]) => return value of method.
*
* Runs OLE method.
* The first argument specifies the method name of OLE Automation object.
* The others specify argument of the <i>method</i>.
* If you can not execute <i>method</i> directly, then use this method instead.
@@ -3036,11 +2972,11 @@
return obj;
}
/*
* call-seq:
- * WIN32OLE#_invoke(dispid, args, types)
+ * _invoke(dispid, args, types)
*
* Runs the early binding method.
* The 1st argument specifies dispatch ID,
* the 2nd argument specifies the array of arguments,
* the 3rd argument specifies the array of the type of arguments.
@@ -3054,11 +2990,11 @@
return ole_invoke2(self, dispid, args, types, DISPATCH_METHOD);
}
/*
* call-seq:
- * WIN32OLE#_getproperty(dispid, args, types)
+ * _getproperty(dispid, args, types)
*
* Runs the early binding method to get property.
* The 1st argument specifies dispatch ID,
* the 2nd argument specifies the array of arguments,
* the 3rd argument specifies the array of the type of arguments.
@@ -3072,11 +3008,11 @@
return ole_invoke2(self, dispid, args, types, DISPATCH_PROPERTYGET);
}
/*
* call-seq:
- * WIN32OLE#_setproperty(dispid, args, types)
+ * _setproperty(dispid, args, types)
*
* Runs the early binding method to set property.
* The 1st argument specifies dispatch ID,
* the 2nd argument specifies the array of arguments,
* the 3rd argument specifies the array of the type of arguments.
@@ -3118,11 +3054,11 @@
return v;
}
/*
* call-seq:
- * WIN32OLE.setproperty('property', [arg1, arg2,...] val)
+ * setproperty('property', [arg1, arg2,...] val)
*
* Sets property of OLE object.
* When you want to set property with argument, you can use this method.
*
* excel = WIN32OLE.new('Excel.Application')
@@ -3224,11 +3160,11 @@
return Qnil;
}
/*
* call-seq:
- * WIN32OLE#ole_free
+ * ole_free
*
* invokes Release method of Dispatch interface of WIN32OLE object.
* Usually, you do not need to call this method because Release method
* called automatically when WIN32OLE object garbaged.
*
@@ -3267,11 +3203,11 @@
return Qnil;
}
/*
* call-seq:
- * WIN32OLE#each {|i|...}
+ * each {|i|...}
*
* Iterates over each item of OLE collection which has IEnumVARIANT interface.
*
* excel = WIN32OLE.new('Excel.Application')
* book = excel.workbooks.add
@@ -3338,11 +3274,11 @@
return Qnil;
}
/*
* call-seq:
- * WIN32OLE#method_missing(id [,arg1, arg2, ...])
+ * method_missing(id [,arg1, arg2, ...])
*
* Calls WIN32OLE#invoke method.
*/
static VALUE
fole_missing(int argc, VALUE *argv, VALUE self)
@@ -3436,13 +3372,13 @@
return methods;
}
/*
* call-seq:
- * WIN32OLE#ole_methods
+ * ole_methods
*
- * Returns the array of WIN32OLE_METHOD object.
+ * Returns the array of WIN32OLE::Method object.
* The element is OLE method of WIN32OLE object.
*
* excel = WIN32OLE.new('Excel.Application')
* methods = excel.ole_methods
*
@@ -3453,13 +3389,13 @@
return ole_methods( self, INVOKE_FUNC | INVOKE_PROPERTYGET | INVOKE_PROPERTYPUT | INVOKE_PROPERTYPUTREF);
}
/*
* call-seq:
- * WIN32OLE#ole_get_methods
+ * ole_get_methods
*
- * Returns the array of WIN32OLE_METHOD object .
+ * Returns the array of WIN32OLE::Method object .
* The element of the array is property (gettable) of WIN32OLE object.
*
* excel = WIN32OLE.new('Excel.Application')
* properties = excel.ole_get_methods
*/
@@ -3469,13 +3405,13 @@
return ole_methods( self, INVOKE_PROPERTYGET);
}
/*
* call-seq:
- * WIN32OLE#ole_put_methods
+ * ole_put_methods
*
- * Returns the array of WIN32OLE_METHOD object .
+ * Returns the array of WIN32OLE::Method object .
* The element of the array is property (settable) of WIN32OLE object.
*
* excel = WIN32OLE.new('Excel.Application')
* properties = excel.ole_put_methods
*/
@@ -3485,13 +3421,13 @@
return ole_methods( self, INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF);
}
/*
* call-seq:
- * WIN32OLE#ole_func_methods
+ * ole_func_methods
*
- * Returns the array of WIN32OLE_METHOD object .
+ * Returns the array of WIN32OLE::Method object .
* The element of the array is property (settable) of WIN32OLE object.
*
* excel = WIN32OLE.new('Excel.Application')
* properties = excel.ole_func_methods
*
@@ -3502,13 +3438,13 @@
return ole_methods( self, INVOKE_FUNC);
}
/*
* call-seq:
- * WIN32OLE#ole_type
+ * ole_type
*
- * Returns WIN32OLE_TYPE object.
+ * Returns WIN32OLE::Type object.
*
* excel = WIN32OLE.new('Excel.Application')
* tobj = excel.ole_type
*/
static VALUE
@@ -3527,20 +3463,20 @@
ole_raise(hr, eWIN32OLEQueryInterfaceError, "failed to GetTypeInfo");
}
type = ole_type_from_itypeinfo(pTypeInfo);
OLE_RELEASE(pTypeInfo);
if (type == Qnil) {
- rb_raise(rb_eRuntimeError, "failed to create WIN32OLE_TYPE obj from ITypeInfo");
+ rb_raise(rb_eRuntimeError, "failed to create WIN32OLE::Type obj from ITypeInfo");
}
return type;
}
/*
* call-seq:
- * WIN32OLE#ole_typelib -> The WIN32OLE_TYPELIB object
+ * ole_typelib -> The WIN32OLE_TYPELIB object
*
- * Returns the WIN32OLE_TYPELIB object. The object represents the
+ * Returns the WIN32OLE::TypeLib object. The object represents the
* type library which contains the WIN32OLE object.
*
* excel = WIN32OLE.new('Excel.Application')
* tlib = excel.ole_typelib
* puts tlib.name # -> 'Microsoft Excel 9.0 Object Library'
@@ -3568,11 +3504,11 @@
return vtlib;
}
/*
* call-seq:
- * WIN32OLE#ole_query_interface(iid) -> WIN32OLE object
+ * ole_query_interface(iid) -> WIN32OLE object
*
* Returns WIN32OLE object for a specific dispatch or dual
* interface specified by iid.
*
* ie = WIN32OLE.new('InternetExplorer.Application')
@@ -3614,11 +3550,11 @@
return create_win32ole_object(cWIN32OLE, pDispatch, 0, 0);
}
/*
* call-seq:
- * WIN32OLE#ole_respond_to?(method) -> true or false
+ * ole_respond_to?(method) -> true or false
*
* Returns true when OLE object has OLE method, otherwise returns false.
*
* ie = WIN32OLE.new('InternetExplorer.Application')
* ie.ole_respond_to?("gohome") => true
@@ -3823,13 +3759,13 @@
return typestr;
}
/*
* call-seq:
- * WIN32OLE#ole_method_help(method)
+ * ole_method_help(method)
*
- * Returns WIN32OLE_METHOD object corresponding with method
+ * Returns WIN32OLE::Method object corresponding with method
* specified by 1st argument.
*
* excel = WIN32OLE.new('Excel.Application')
* method = excel.ole_method_help('Quit')
*
@@ -3857,11 +3793,11 @@
return obj;
}
/*
* call-seq:
- * WIN32OLE#ole_activex_initialize() -> Qnil
+ * ole_activex_initialize() -> Qnil
*
* Initialize WIN32OLE object(ActiveX Control) by calling
* IPersistMemory::InitNew.
*
* Before calling OLE method, some kind of the ActiveX controls
@@ -4071,10 +4007,10 @@
* c = 0
* comserver.calcsum(a, b, c)
* p c # => 0
* p WIN32OLE::ARGV # => [10, 20, 30]
*
- * You can use WIN32OLE_VARIANT object to retrieve the value of reference
+ * You can use WIN32OLE::Variant object to retrieve the value of reference
* arguments instead of referring WIN32OLE::ARGV.
*
*/
rb_define_const(cWIN32OLE, "ARGV", rb_ary_new());