Method: WIN32OLE.const_load
- Defined in:
- win32ole.c
.const_load(ole, mod = WIN32OLE) ⇒ Object
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, so constant variable name of WIN32OLE object is capitalized. For example, the ‘xlTop’ constant of Excel is changed to ‘XlTop’ in WIN32OLE. If the first letter of constant variable is not [A-Z], then the constant is defined as CONSTANTS hash element.
module EXCEL_CONST
end
excel = WIN32OLE.new('Excel.Application')
WIN32OLE.const_load(excel, EXCEL_CONST)
puts EXCEL_CONST::XlTop # => -4160
puts EXCEL_CONST::CONSTANTS['_xlDialogChartSourceData'] # => 541
WIN32OLE.const_load(excel)
puts WIN32OLE::XlTop # => -4160
module MSO
end
WIN32OLE.const_load('Microsoft Office 9.0 Object Library', MSO)
puts MSO::MsoLineSingle # => 1
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 |
# File 'win32ole.c', line 2049
static VALUE
fole_s_const_load(int argc, VALUE *argv, VALUE self)
{
VALUE ole;
VALUE klass;
struct oledata *pole = NULL;
ITypeInfo *pTypeInfo;
ITypeLib *pTypeLib;
unsigned int index;
HRESULT hr;
OLECHAR *pBuf;
VALUE file;
LCID lcid = cWIN32OLE_lcid;
rb_scan_args(argc, argv, "11", &ole, &klass);
if (!RB_TYPE_P(klass, T_CLASS) &&
!RB_TYPE_P(klass, T_MODULE) &&
!RB_TYPE_P(klass, T_NIL)) {
rb_raise(rb_eTypeError, "2nd parameter must be Class or Module");
}
if (rb_obj_is_kind_of(ole, cWIN32OLE)) {
pole = oledata_get_struct(ole);
hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
0, lcid, &pTypeInfo);
if(FAILED(hr)) {
ole_raise(hr, eWIN32OLEQueryInterfaceError, "failed to GetTypeInfo");
}
hr = pTypeInfo->lpVtbl->GetContainingTypeLib(pTypeInfo, &pTypeLib, &index);
if(FAILED(hr)) {
OLE_RELEASE(pTypeInfo);
ole_raise(hr, eWIN32OLEQueryInterfaceError, "failed to GetContainingTypeLib");
}
OLE_RELEASE(pTypeInfo);
if(!RB_TYPE_P(klass, T_NIL)) {
ole_const_load(pTypeLib, klass, self);
}
else {
ole_const_load(pTypeLib, cWIN32OLE, self);
}
OLE_RELEASE(pTypeLib);
}
else if(RB_TYPE_P(ole, T_STRING)) {
file = typelib_file(ole);
if (file == Qnil) {
file = ole;
}
pBuf = ole_vstr2wc(file);
hr = LoadTypeLibEx(pBuf, REGKIND_NONE, &pTypeLib);
SysFreeString(pBuf);
if (FAILED(hr))
ole_raise(hr, eWIN32OLERuntimeError, "failed to LoadTypeLibEx");
if(!RB_TYPE_P(klass, T_NIL)) {
ole_const_load(pTypeLib, klass, self);
}
else {
ole_const_load(pTypeLib, cWIN32OLE, self);
}
OLE_RELEASE(pTypeLib);
}
else {
rb_raise(rb_eTypeError, "1st parameter must be WIN32OLE instance");
}
return Qnil;
}
|