mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/win32ole/win32ole.c: use typed data for WIN32OLE.
* ext/win32ole/win32ole.h: ditto. * ext/win32ole/win32ole_event.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
15cfc9553a
commit
7f411d6ed4
4 changed files with 73 additions and 52 deletions
|
@ -1,3 +1,9 @@
|
|||
Mon Dec 1 20:01:12 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c: use typed data for WIN32OLE.
|
||||
* ext/win32ole/win32ole.h: ditto.
|
||||
* ext/win32ole/win32ole_event.c: ditto.
|
||||
|
||||
Mon Dec 1 17:20:42 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* win32/Makefile.sub (verconf.h): so depends on verconf.mk, which
|
||||
|
|
|
@ -97,7 +97,8 @@ static void load_conv_function51932(void);
|
|||
static UINT ole_init_cp(void);
|
||||
static void ole_freeexceptinfo(EXCEPINFO *pExInfo);
|
||||
static VALUE ole_excepinfo2msg(EXCEPINFO *pExInfo);
|
||||
static void ole_free(struct oledata *pole);
|
||||
static void ole_free(void *ptr);
|
||||
static size_t ole_size(const void *ptr);
|
||||
static LPWSTR ole_mb2wc(char *pm, int len);
|
||||
static VALUE ole_ary_m_entry(VALUE val, LONG *pid);
|
||||
static VALUE is_all_index_under(LONG *pid, long *pub, long dim);
|
||||
|
@ -168,6 +169,12 @@ static VALUE fole_activex_initialize(VALUE self);
|
|||
static void init_enc2cp(void);
|
||||
static void free_enc2cp(void);
|
||||
|
||||
static const rb_data_type_t ole_datatype = {
|
||||
"win32ole",
|
||||
{NULL, ole_free, ole_size,},
|
||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
||||
};
|
||||
|
||||
static HRESULT (STDMETHODCALLTYPE mf_QueryInterface)(
|
||||
IMessageFilter __RPC_FAR * This,
|
||||
/* [in] */ REFIID riid,
|
||||
|
@ -813,12 +820,26 @@ ole_initialize(void)
|
|||
}
|
||||
|
||||
static void
|
||||
ole_free(struct oledata *pole)
|
||||
ole_free(void *ptr)
|
||||
{
|
||||
struct oledata *pole = ptr;
|
||||
OLE_FREE(pole->pDispatch);
|
||||
free(pole);
|
||||
}
|
||||
|
||||
static size_t ole_size(const void *ptr)
|
||||
{
|
||||
return ptr ? sizeof(struct oledata) : 0;
|
||||
}
|
||||
|
||||
struct oledata *
|
||||
oledata_get_struct(VALUE ole)
|
||||
{
|
||||
struct oledata *pole;
|
||||
TypedData_Get_Struct(ole, struct oledata, &ole_datatype, pole);
|
||||
return pole;
|
||||
}
|
||||
|
||||
LPWSTR
|
||||
ole_vstr2wc(VALUE vstr)
|
||||
{
|
||||
|
@ -1216,9 +1237,9 @@ ole_val_ary2variant_ary(VALUE val, VARIANT *var, VARTYPE vt)
|
|||
void
|
||||
ole_val2variant(VALUE val, VARIANT *var)
|
||||
{
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
if(rb_obj_is_kind_of(val, cWIN32OLE)) {
|
||||
Data_Get_Struct(val, struct oledata, pole);
|
||||
pole = oledata_get_struct(val);
|
||||
OLE_ADDREF(pole->pDispatch);
|
||||
V_VT(var) = VT_DISPATCH;
|
||||
V_DISPATCH(var) = pole->pDispatch;
|
||||
|
@ -1310,8 +1331,8 @@ default_inspect(VALUE self, const char *class_name)
|
|||
static VALUE
|
||||
ole_set_member(VALUE self, IDispatch *dispatch)
|
||||
{
|
||||
struct oledata *pole;
|
||||
Data_Get_Struct(self, struct oledata, pole);
|
||||
struct oledata *pole = NULL;
|
||||
pole = oledata_get_struct(self);
|
||||
if (pole->pDispatch) {
|
||||
OLE_RELEASE(pole->pDispatch);
|
||||
pole->pDispatch = NULL;
|
||||
|
@ -1327,7 +1348,7 @@ fole_s_allocate(VALUE klass)
|
|||
struct oledata *pole;
|
||||
VALUE obj;
|
||||
ole_initialize();
|
||||
obj = Data_Make_Struct(klass,struct oledata,0,ole_free,pole);
|
||||
obj = TypedData_Make_Struct(klass, struct oledata, &ole_datatype, pole);
|
||||
pole->pDispatch = NULL;
|
||||
return obj;
|
||||
}
|
||||
|
@ -2007,7 +2028,7 @@ fole_s_const_load(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
VALUE ole;
|
||||
VALUE klass;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
ITypeInfo *pTypeInfo;
|
||||
ITypeLib *pTypeLib;
|
||||
unsigned int index;
|
||||
|
@ -2023,7 +2044,7 @@ fole_s_const_load(int argc, VALUE *argv, VALUE self)
|
|||
rb_raise(rb_eTypeError, "2nd parameter must be Class or Module");
|
||||
}
|
||||
if (rb_obj_is_kind_of(ole, cWIN32OLE)) {
|
||||
OLEData_Get_Struct(ole, pole);
|
||||
pole = oledata_get_struct(ole);
|
||||
hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
|
||||
0, lcid, &pTypeInfo);
|
||||
if(FAILED(hr)) {
|
||||
|
@ -2089,8 +2110,8 @@ reference_count(struct oledata * pole)
|
|||
static VALUE
|
||||
fole_s_reference_count(VALUE self, VALUE obj)
|
||||
{
|
||||
struct oledata * pole;
|
||||
OLEData_Get_Struct(obj, pole);
|
||||
struct oledata * pole = NULL;
|
||||
pole = oledata_get_struct(obj);
|
||||
return INT2NUM(reference_count(pole));
|
||||
}
|
||||
|
||||
|
@ -2107,8 +2128,8 @@ static VALUE
|
|||
fole_s_free(VALUE self, VALUE obj)
|
||||
{
|
||||
ULONG n = 0;
|
||||
struct oledata * pole;
|
||||
OLEData_Get_Struct(obj, pole);
|
||||
struct oledata * pole = NULL;
|
||||
pole = oledata_get_struct(obj);
|
||||
if(pole->pDispatch) {
|
||||
if (reference_count(pole) > 0) {
|
||||
n = OLE_RELEASE(pole->pDispatch);
|
||||
|
@ -2516,7 +2537,7 @@ static VALUE
|
|||
ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
|
||||
{
|
||||
LCID lcid = cWIN32OLE_lcid;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
HRESULT hr;
|
||||
VALUE cmd;
|
||||
VALUE paramS;
|
||||
|
@ -2552,7 +2573,7 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
|
|||
if (RB_TYPE_P(cmd, T_SYMBOL)) {
|
||||
cmd = rb_sym_to_s(cmd);
|
||||
}
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
if(!pole->pDispatch) {
|
||||
rb_raise(rb_eRuntimeError, "failed to get dispatch interface");
|
||||
}
|
||||
|
@ -2773,7 +2794,7 @@ static VALUE
|
|||
ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
|
||||
{
|
||||
HRESULT hr;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
unsigned int argErr = 0;
|
||||
EXCEPINFO excepinfo;
|
||||
VARIANT result;
|
||||
|
@ -2791,7 +2812,7 @@ ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
|
|||
memset(&excepinfo, 0, sizeof(EXCEPINFO));
|
||||
memset(&dispParams, 0, sizeof(DISPPARAMS));
|
||||
VariantInit(&result);
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
|
||||
dispParams.cArgs = RARRAY_LEN(args);
|
||||
dispParams.rgvarg = ALLOCA_N(VARIANTARG, dispParams.cArgs);
|
||||
|
@ -3081,7 +3102,7 @@ fole_getproperty_with_bracket(int argc, VALUE *argv, VALUE self)
|
|||
static VALUE
|
||||
ole_propertyput(VALUE self, VALUE property, VALUE value)
|
||||
{
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
unsigned argErr;
|
||||
unsigned int index;
|
||||
HRESULT hr;
|
||||
|
@ -3103,7 +3124,7 @@ ole_propertyput(VALUE self, VALUE property, VALUE value)
|
|||
VariantInit(&propertyValue[1]);
|
||||
memset(&excepinfo, 0, sizeof(excepinfo));
|
||||
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
|
||||
/* get ID from property name */
|
||||
pBuf[0] = ole_vstr2wc(property);
|
||||
|
@ -3147,8 +3168,8 @@ ole_propertyput(VALUE self, VALUE property, VALUE value)
|
|||
static VALUE
|
||||
fole_free(VALUE self)
|
||||
{
|
||||
struct oledata *pole;
|
||||
OLEData_Get_Struct(self, pole);
|
||||
struct oledata *pole = NULL;
|
||||
pole = oledata_get_struct(self);
|
||||
OLE_FREE(pole->pDispatch);
|
||||
pole->pDispatch = NULL;
|
||||
return Qnil;
|
||||
|
@ -3197,7 +3218,7 @@ fole_each(VALUE self)
|
|||
{
|
||||
LCID lcid = cWIN32OLE_lcid;
|
||||
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
|
||||
unsigned int argErr;
|
||||
EXCEPINFO excepinfo;
|
||||
|
@ -3216,7 +3237,7 @@ fole_each(VALUE self)
|
|||
dispParams.cArgs = 0;
|
||||
memset(&excepinfo, 0, sizeof(excepinfo));
|
||||
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DISPID_NEWENUM,
|
||||
&IID_NULL, lcid,
|
||||
DISPATCH_METHOD | DISPATCH_PROPERTYGET,
|
||||
|
@ -3332,9 +3353,9 @@ ole_methods(VALUE self, int mask)
|
|||
ITypeInfo *pTypeInfo;
|
||||
HRESULT hr;
|
||||
VALUE methods;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
methods = rb_ary_new();
|
||||
|
||||
hr = typeinfo_from_ole(pole, &pTypeInfo);
|
||||
|
@ -3425,11 +3446,11 @@ fole_type(VALUE self)
|
|||
{
|
||||
ITypeInfo *pTypeInfo;
|
||||
HRESULT hr;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
LCID lcid = cWIN32OLE_lcid;
|
||||
VALUE type = Qnil;
|
||||
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
|
||||
hr = pole->pDispatch->lpVtbl->GetTypeInfo( pole->pDispatch, 0, lcid, &pTypeInfo );
|
||||
if(FAILED(hr)) {
|
||||
|
@ -3457,13 +3478,13 @@ fole_type(VALUE self)
|
|||
static VALUE
|
||||
fole_typelib(VALUE self)
|
||||
{
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
HRESULT hr;
|
||||
ITypeInfo *pTypeInfo;
|
||||
LCID lcid = cWIN32OLE_lcid;
|
||||
VALUE vtlib = Qnil;
|
||||
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
|
||||
0, lcid, &pTypeInfo);
|
||||
if(FAILED(hr)) {
|
||||
|
@ -3493,7 +3514,7 @@ fole_query_interface(VALUE self, VALUE str_iid)
|
|||
HRESULT hr;
|
||||
OLECHAR *pBuf;
|
||||
IID iid;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
IDispatch *pDispatch;
|
||||
void *p;
|
||||
|
||||
|
@ -3506,7 +3527,7 @@ fole_query_interface(VALUE self, VALUE str_iid)
|
|||
StringValuePtr(str_iid));
|
||||
}
|
||||
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
if(!pole->pDispatch) {
|
||||
rb_raise(rb_eRuntimeError, "failed to get dispatch interface");
|
||||
}
|
||||
|
@ -3535,7 +3556,7 @@ fole_query_interface(VALUE self, VALUE str_iid)
|
|||
static VALUE
|
||||
fole_respond_to(VALUE self, VALUE method)
|
||||
{
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
BSTR wcmdname;
|
||||
DISPID DispID;
|
||||
HRESULT hr;
|
||||
|
@ -3545,7 +3566,7 @@ fole_respond_to(VALUE self, VALUE method)
|
|||
if (RB_TYPE_P(method, T_SYMBOL)) {
|
||||
method = rb_sym_to_s(method);
|
||||
}
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
wcmdname = ole_vstr2wc(method);
|
||||
hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL,
|
||||
&wcmdname, 1, cWIN32OLE_lcid, &DispID);
|
||||
|
@ -3748,11 +3769,11 @@ fole_method_help(VALUE self, VALUE cmdname)
|
|||
{
|
||||
ITypeInfo *pTypeInfo;
|
||||
HRESULT hr;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
VALUE obj;
|
||||
|
||||
SafeStringValue(cmdname);
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
hr = typeinfo_from_ole(pole, &pTypeInfo);
|
||||
if(FAILED(hr))
|
||||
ole_raise(hr, rb_eRuntimeError, "failed to get ITypeInfo");
|
||||
|
@ -3789,13 +3810,13 @@ fole_method_help(VALUE self, VALUE cmdname)
|
|||
static VALUE
|
||||
fole_activex_initialize(VALUE self)
|
||||
{
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
IPersistMemory *pPersistMemory;
|
||||
void *p;
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
OLEData_Get_Struct(self, pole);
|
||||
pole = oledata_get_struct(self);
|
||||
|
||||
hr = pole->pDispatch->lpVtbl->QueryInterface(pole->pDispatch, &IID_IPersistMemory, &p);
|
||||
pPersistMemory = p;
|
||||
|
@ -3819,10 +3840,10 @@ typelib_from_val(VALUE obj, ITypeLib **pTypeLib)
|
|||
{
|
||||
LCID lcid = cWIN32OLE_lcid;
|
||||
HRESULT hr;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
unsigned int index;
|
||||
ITypeInfo *pTypeInfo;
|
||||
OLEData_Get_Struct(obj, pole);
|
||||
pole = oledata_get_struct(obj);
|
||||
hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
|
||||
0, lcid, &pTypeInfo);
|
||||
if (FAILED(hr)) {
|
||||
|
|
|
@ -112,16 +112,10 @@ struct oledata {
|
|||
IDispatch *pDispatch;
|
||||
};
|
||||
|
||||
#define OLEData_Get_Struct(obj, pole) {\
|
||||
Data_Get_Struct(obj, struct oledata, pole);\
|
||||
if(!pole->pDispatch) {\
|
||||
rb_raise(rb_eRuntimeError, "failed to get Dispatch Interface");\
|
||||
}\
|
||||
}
|
||||
|
||||
VALUE cWIN32OLE;
|
||||
LCID cWIN32OLE_lcid;
|
||||
|
||||
struct oledata *oledata_get_struct(VALUE obj);
|
||||
LPWSTR ole_vstr2wc(VALUE vstr);
|
||||
LONG reg_open_key(HKEY hkey, const char *name, HKEY *phkey);
|
||||
LONG reg_open_vkey(HKEY hkey, VALUE key, HKEY *phkey);
|
||||
|
|
|
@ -485,7 +485,7 @@ find_iid(VALUE ole, char *pitf, IID *piid, ITypeInfo **ppTypeInfo)
|
|||
ITypeInfo *pImplTypeInfo;
|
||||
TYPEATTR *pImplTypeAttr;
|
||||
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
unsigned int index;
|
||||
unsigned int count;
|
||||
int type;
|
||||
|
@ -495,7 +495,7 @@ find_iid(VALUE ole, char *pitf, IID *piid, ITypeInfo **ppTypeInfo)
|
|||
BOOL is_found = FALSE;
|
||||
LCID lcid = cWIN32OLE_lcid;
|
||||
|
||||
OLEData_Get_Struct(ole, pole);
|
||||
pole = oledata_get_struct(ole);
|
||||
|
||||
pDispatch = pole->pDispatch;
|
||||
|
||||
|
@ -709,9 +709,9 @@ find_default_source(VALUE ole, IID *piid, ITypeInfo **ppTypeInfo)
|
|||
TYPEATTR *pTypeAttr;
|
||||
TYPEATTR *pTypeAttr2 = NULL;
|
||||
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
|
||||
OLEData_Get_Struct(ole, pole);
|
||||
pole = oledata_get_struct(ole);
|
||||
pDispatch = pole->pDispatch;
|
||||
hr = pDispatch->lpVtbl->QueryInterface(pDispatch,
|
||||
&IID_IProvideClassInfo2,
|
||||
|
@ -896,7 +896,7 @@ ev_advise(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
|
||||
VALUE ole, itf;
|
||||
struct oledata *pole;
|
||||
struct oledata *pole = NULL;
|
||||
char *pitf;
|
||||
HRESULT hr;
|
||||
IID iid;
|
||||
|
@ -930,7 +930,7 @@ ev_advise(int argc, VALUE *argv, VALUE self)
|
|||
ole_raise(hr, rb_eRuntimeError, "interface not found");
|
||||
}
|
||||
|
||||
OLEData_Get_Struct(ole, pole);
|
||||
pole = oledata_get_struct(ole);
|
||||
pDispatch = pole->pDispatch;
|
||||
hr = pDispatch->lpVtbl->QueryInterface(pDispatch,
|
||||
&IID_IConnectionPointContainer,
|
||||
|
|
Loading…
Reference in a new issue