summaryrefslogtreecommitdiff
path: root/ext/win32ole/win32ole_event.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/win32ole/win32ole_event.c')
-rw-r--r--ext/win32ole/win32ole_event.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/ext/win32ole/win32ole_event.c b/ext/win32ole/win32ole_event.c
index 2cceae7af7..fdd2c46e99 100644
--- a/ext/win32ole/win32ole_event.c
+++ b/ext/win32ole/win32ole_event.c
@@ -86,7 +86,8 @@ static long ole_search_event_at(VALUE ary, VALUE ev);
static VALUE ole_search_event(VALUE ary, VALUE ev, BOOL *is_default);
static VALUE ole_search_handler_method(VALUE handler, VALUE ev, BOOL *is_default_handler);
static void ole_delete_event(VALUE ary, VALUE ev);
-static void ole_event_free(struct oleeventdata *poleev);
+static void oleevent_free(void *ptr);
+static size_t oleevent_size(const void *ptr);
static VALUE fev_s_allocate(VALUE klass);
static VALUE ev_advise(int argc, VALUE *argv, VALUE self);
static VALUE fev_initialize(int argc, VALUE *argv, VALUE self);
@@ -105,6 +106,13 @@ static VALUE evs_delete(long i);
static VALUE evs_entry(long i);
static long evs_length(void);
+
+static const rb_data_type_t oleevent_datatype = {
+ "win32ole_event",
+ {NULL, oleevent_free, oleevent_size,},
+ NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
STDMETHODIMP EVENTSINK_Invoke(
PEVENTSINK pEventSink,
DISPID dispid,
@@ -852,8 +860,9 @@ ole_delete_event(VALUE ary, VALUE ev)
static void
-ole_event_free(struct oleeventdata *poleev)
+oleevent_free(void *ptr)
{
+ struct oleeventdata *poleev = ptr;
if (poleev->pConnectionPoint) {
poleev->pConnectionPoint->lpVtbl->Unadvise(poleev->pConnectionPoint, poleev->dwCookie);
OLE_RELEASE(poleev->pConnectionPoint);
@@ -863,12 +872,18 @@ ole_event_free(struct oleeventdata *poleev)
free(poleev);
}
+static size_t
+oleevent_size(const void *ptr)
+{
+ return ptr ? sizeof(struct oleeventdata) : 0;
+}
+
static VALUE
fev_s_allocate(VALUE klass)
{
VALUE obj;
struct oleeventdata *poleev;
- obj = Data_Make_Struct(klass,struct oleeventdata,0,ole_event_free,poleev);
+ obj = TypedData_Make_Struct(klass, struct oleeventdata, &oleevent_datatype, poleev);
poleev->dwCookie = 0;
poleev->pConnectionPoint = NULL;
poleev->event_id = 0;
@@ -944,7 +959,7 @@ ev_advise(int argc, VALUE *argv, VALUE self)
ole_raise(hr, rb_eRuntimeError, "Advise Error");
}
- Data_Get_Struct(self, struct oleeventdata, poleev);
+ TypedData_Get_Struct(self, struct oleeventdata, &oleevent_datatype, poleev);
pIEV->m_event_id = evs_length();
pIEV->pTypeInfo = pTypeInfo;
poleev->dwCookie = dwCookie;
@@ -1016,7 +1031,7 @@ ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg)
{
struct oleeventdata *poleev;
VALUE event, args, data;
- Data_Get_Struct(self, struct oleeventdata, poleev);
+ TypedData_Get_Struct(self, struct oleeventdata, &oleevent_datatype, poleev);
if (poleev->pConnectionPoint == NULL) {
rb_raise(eWIN32OLERuntimeError, "IConnectionPoint not found. You must call advise at first.");
}
@@ -1146,7 +1161,7 @@ static VALUE
fev_unadvise(VALUE self)
{
struct oleeventdata *poleev;
- Data_Get_Struct(self, struct oleeventdata, poleev);
+ TypedData_Get_Struct(self, struct oleeventdata, &oleevent_datatype, poleev);
if (poleev->pConnectionPoint) {
ole_msg_loop();
evs_delete(poleev->event_id);