Method: WIN32OLE::Record#initialize
- Defined in:
- win32ole_record.c
#new(typename, obj) ⇒ WIN32OLE::Record object
Returns WIN32OLE::Record object. The first argument is struct name (String or Symbol). The second parameter obj should be WIN32OLE object or WIN32OLE::TypeLib object. If COM server in VB.NET ComServer project is the following:
Imports System.Runtime.InteropServices
Public Class ComClass
Public Structure Book
<MarshalAs(UnmanagedType.BStr)> _
Public title As String
Public cost As Integer
End Structure
End Class
then, you can create WIN32OLE::Record object is as following:
require 'win32ole'
obj = WIN32OLE.new('ComServer.ComClass')
book1 = WIN32OLE::Record.new('Book', obj) # => WIN32OLE::Record object
tlib = obj.ole_typelib
book2 = WIN32OLE::Record.new('Book', tlib) # => WIN32OLE::Record object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'win32ole_record.c', line 281 static VALUE folerecord_initialize(VALUE self, VALUE typename, VALUE oleobj) { HRESULT hr; ITypeLib *pTypeLib = NULL; IRecordInfo *pri = NULL; if (!RB_TYPE_P(typename, T_STRING) && !RB_TYPE_P(typename, T_SYMBOL)) { rb_raise(rb_eArgError, "1st argument should be String or Symbol"); } if (RB_TYPE_P(typename, T_SYMBOL)) { typename = rb_sym2str(typename); } hr = S_OK; if(rb_obj_is_kind_of(oleobj, cWIN32OLE)) { hr = typelib_from_val(oleobj, &pTypeLib); } else if (rb_obj_is_kind_of(oleobj, cWIN32OLE_TYPELIB)) { pTypeLib = itypelib(oleobj); OLE_ADDREF(pTypeLib); if (pTypeLib) { hr = S_OK; } else { hr = E_FAIL; } } else { rb_raise(rb_eArgError, "2nd argument should be WIN32OLE object or WIN32OLE::TypeLib object"); } if (FAILED(hr)) { ole_raise(hr, eWIN32OLERuntimeError, "fail to query ITypeLib interface"); } hr = recordinfo_from_itypelib(pTypeLib, typename, &pri); OLE_RELEASE(pTypeLib); if (FAILED(hr)) { ole_raise(hr, eWIN32OLERuntimeError, "fail to query IRecordInfo interface for `%s'", StringValuePtr(typename)); } olerecord_set_ivar(self, pri, NULL); return self; } |