7 static VALUE reg_get_typelib_file_path(HKEY hkey);
9 static HRESULT oletypelib_from_guid(
VALUE guid,
VALUE version, ITypeLib **ppTypeLib);
10 static VALUE foletypelib_s_typelibs(
VALUE self);
12 static void oletypelib_free(
void *ptr);
13 static size_t oletypelib_size(
const void *ptr);
14 static VALUE foletypelib_s_allocate(
VALUE klass);
16 static void oletypelib_get_libattr(ITypeLib *
pTypeLib, TLIBATTR **ppTLibAttr);
23 static VALUE foletypelib_major_version(
VALUE self);
24 static VALUE foletypelib_minor_version(
VALUE self);
27 static VALUE foletypelib_library_name(
VALUE self);
29 static VALUE typelib_file_from_typelib(
VALUE ole);
30 static VALUE typelib_file_from_clsid(
VALUE ole);
31 static VALUE foletypelib_ole_types(
VALUE self);
36 {
NULL, oletypelib_free, oletypelib_size,},
41 reg_get_typelib_file_path(HKEY hkey)
72 if (err != ERROR_SUCCESS) {
75 for(k = 0; path ==
Qnil; k++) {
80 if (err == ERROR_SUCCESS) {
81 path = reg_get_typelib_file_path(hlang);
90 oletypelib_from_guid(
VALUE guid,
VALUE version, ITypeLib **ppTypeLib)
95 path = oletypelib_path(guid, version);
100 hr = LoadTypeLibEx(pBuf, REGKIND_NONE, ppTypeLib);
121 hr = pTypeInfo->lpVtbl->GetContainingTypeLib(pTypeInfo, &pTypeLib, &index);
146 foletypelib_s_typelibs(
VALUE self)
148 HKEY htypelib, hguid;
159 err =
reg_open_key(HKEY_CLASSES_ROOT,
"TypeLib", &htypelib);
160 if(err != ERROR_SUCCESS) {
168 if (err != ERROR_SUCCESS)
175 hr = oletypelib_from_guid(guid, version, &pTypeLib);
184 RegCloseKey(htypelib);
198 oletypelib_free(
void *ptr)
206 oletypelib_size(
const void *ptr)
212 foletypelib_s_allocate(VALUE klass)
226 oletypelib_set_member(obj, pTypeLib);
231 oletypelib_search_registry(
VALUE self,
VALUE typelib)
233 HKEY htypelib, hguid, hversion;
243 err =
reg_open_key(HKEY_CLASSES_ROOT,
"TypeLib", &htypelib);
244 if(err != ERROR_SUCCESS) {
247 for(i = 0; !found; i++) {
252 if (err != ERROR_SUCCESS)
254 for(j = 0; found ==
Qfalse; j++) {
259 if (err != ERROR_SUCCESS)
263 RegCloseKey(hversion);
267 hr = oletypelib_from_guid(guid, ver, &pTypeLib);
269 oletypelib_set_member(
self, pTypeLib);
273 RegCloseKey(hversion);
277 RegCloseKey(htypelib);
282 oletypelib_get_libattr(ITypeLib *pTypeLib, TLIBATTR **ppTLibAttr)
285 hr = pTypeLib->lpVtbl->GetLibAttr(pTypeLib, ppTLibAttr);
288 "failed to get library attribute(TLIBATTR) from ITypeLib");
293 oletypelib_search_registry2(
VALUE self,
VALUE args)
295 HKEY htypelib, hguid, hversion;
311 err =
reg_open_key(HKEY_CLASSES_ROOT,
"TypeLib", &htypelib);
312 if(err != ERROR_SUCCESS) {
316 if (err != ERROR_SUCCESS) {
317 RegCloseKey(htypelib);
320 if (version_str !=
Qnil) {
322 if (err == ERROR_SUCCESS) {
326 version = version_str;
329 RegCloseKey(hversion);
337 if (err != ERROR_SUCCESS)
341 RegCloseKey(hversion);
349 RegCloseKey(hversion);
353 RegCloseKey(htypelib);
354 if (typelib !=
Qnil) {
355 hr = oletypelib_from_guid(guid, version, &pTypeLib);
358 oletypelib_set_member(
self, pTypeLib);
392 foletypelib_initialize(
VALUE self,
VALUE args)
408 found = oletypelib_search_registry(
self, typelib);
410 found = oletypelib_search_registry2(
self, args);
414 hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
418 oletypelib_set_member(
self, pTypeLib);
439 foletypelib_guid(
VALUE self)
448 oletypelib_get_libattr(pTypeLib, &pTLibAttr);
449 len = StringFromGUID2(&pTLibAttr->guid, bstr,
sizeof(bstr)/
sizeof(OLECHAR));
453 pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
467 foletypelib_name(
VALUE self)
474 hr = pTypeLib->lpVtbl->GetDocumentation(pTypeLib, -1,
511 foletypelib_version(
VALUE self)
518 oletypelib_get_libattr(pTypeLib, &pTLibAttr);
519 version =
rb_sprintf(
"%d.%d", pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
520 pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
534 foletypelib_major_version(
VALUE self)
540 oletypelib_get_libattr(pTypeLib, &pTLibAttr);
543 pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
557 foletypelib_minor_version(
VALUE self)
563 oletypelib_get_libattr(pTypeLib, &pTLibAttr);
565 pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
579 foletypelib_path(
VALUE self)
589 oletypelib_get_libattr(pTypeLib, &pTLibAttr);
590 hr = QueryPathOfRegTypeLib(&pTLibAttr->guid,
591 pTLibAttr->wMajorVerNum,
592 pTLibAttr->wMinorVerNum,
596 pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
600 pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
619 foletypelib_visible(
VALUE self)
621 ITypeLib *pTypeLib =
NULL;
626 oletypelib_get_libattr(pTypeLib, &pTLibAttr);
628 if ((pTLibAttr->wLibFlags == 0) ||
629 (pTLibAttr->wLibFlags & LIBFLAG_FRESTRICTED) ||
630 (pTLibAttr->wLibFlags & LIBFLAG_FHIDDEN)) {
633 pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
648 foletypelib_library_name(
VALUE self)
651 ITypeLib *pTypeLib =
NULL;
656 hr = pTypeLib->lpVtbl->GetDocumentation(pTypeLib, -1,
666 ole_types_from_typelib(ITypeLib *pTypeLib,
VALUE classes)
672 ITypeInfo *pTypeInfo;
675 count = pTypeLib->lpVtbl->GetTypeInfoCount(pTypeLib);
676 for (i = 0; i <
count; i++) {
677 hr = pTypeLib->lpVtbl->GetDocumentation(pTypeLib, i,
682 hr = pTypeLib->lpVtbl->GetTypeInfo(pTypeLib, i, &pTypeInfo);
695 typelib_file_from_typelib(
VALUE ole)
697 HKEY htypelib, hclsid, hversion, hlang;
708 err =
reg_open_key(HKEY_CLASSES_ROOT,
"TypeLib", &htypelib);
709 if(err != ERROR_SUCCESS) {
712 for(i = 0; !found; i++) {
717 if (err != ERROR_SUCCESS)
720 for(j = 0; !found; j++) {
732 for(k = 0; !found; k++) {
737 if (err == ERROR_SUCCESS) {
738 if ((file = reg_get_typelib_file_path(hlang)) !=
Qnil)
744 RegCloseKey(hversion);
748 RegCloseKey(htypelib);
753 typelib_file_from_clsid(
VALUE ole)
758 char path[MAX_PATH + 1];
761 if (err != ERROR_SUCCESS) {
765 if (err != ERROR_SUCCESS) {
772 if (typelib !=
Qnil) {
773 ExpandEnvironmentStrings(
StringValuePtr(typelib), path,
sizeof(path));
774 path[MAX_PATH] =
'\0';
783 VALUE file = typelib_file_from_clsid(ole);
787 return typelib_file_from_typelib(ole);
801 foletypelib_ole_types(
VALUE self)
803 ITypeLib *pTypeLib =
NULL;
806 ole_types_from_typelib(pTypeLib, classes);
820 foletypelib_inspect(
VALUE self)
VALUE eWIN32OLERuntimeError
VALUE rb_ary_entry(VALUE ary, long offset)
#define RUBY_TYPED_FREE_IMMEDIATELY
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
void rb_raise(VALUE exc, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
ITypeLib * itypelib(VALUE self)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_str_concat(VALUE, VALUE)
LPWSTR ole_vstr2wc(VALUE vstr)
VALUE rb_String(VALUE)
Equivalent to Kernel#String in Ruby.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
void ole_initialize(void)
VALUE reg_get_val(HKEY hkey, const char *subkey)
int rb_str_cmp(VALUE, VALUE)
VALUE create_win32ole_typelib(ITypeLib *pTypeLib)
void ole_raise(HRESULT hr, VALUE ecs, const char *fmt,...)
VALUE default_inspect(VALUE self, const char *class_name)
RUBY_EXTERN VALUE rb_cObject
VALUE reg_get_val2(HKEY hkey, const char *subkey)
VALUE rb_str_cat2(VALUE, const char *)
VALUE typelib_file(VALUE ole)
LONG reg_open_key(HKEY hkey, const char *name, HKEY *phkey)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
LONG reg_open_vkey(HKEY hkey, VALUE key, HKEY *phkey)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
VALUE rb_sprintf(const char *format,...)
register unsigned int len
void Init_win32ole_typelib(void)
VALUE ole_wc2vstr(LPWSTR pw, BOOL isfree)
typedef HRESULT(STDAPICALLTYPE FNCOCREATEINSTANCEEX)(REFCLSID
VALUE reg_enum_key(HKEY hkey, DWORD i)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE ole_typelib_from_itypeinfo(ITypeInfo *pTypeInfo)
#define SafeStringValue(v)
#define StringValuePtr(v)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
VALUE create_win32ole_type(ITypeInfo *pTypeInfo, VALUE name)