1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

add WIN32OLE.create_guid.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2006-02-11 13:00:46 +00:00
parent 898f5b315c
commit 9a59edfb4e
3 changed files with 40 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Sat Feb 11 21:57:29 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: add WIN32OLE.create_guid.
* ext/win32ole/tests/testWIN32OLE.rb: ditto.
Tue Feb 7 23:03:13 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/zlib/zlib.c: should not access ruby objects in finalizer.

View file

@ -289,6 +289,12 @@ class TestWin32OLE < RUNIT::TestCase
assert_equal(tlib.name, MS_EXCEL_TYPELIB);
end
def test_s_create_guid
guid = WIN32OLE.create_guid
assert_match(/^\{[A-Z0-9]{8}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{12}/,
guid)
end
def teardown
@excel.quit
@excel = nil

View file

@ -79,7 +79,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
#define WIN32OLE_VERSION "0.6.9"
#define WIN32OLE_VERSION "0.7.0"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@ -2023,6 +2023,32 @@ fole_s_set_code_page(self, vcp)
return Qnil;
}
/*
* call-seq:
* WIN32OLE.create_guid
*
* Creates GUID.
* WIN32OLE.create_guid # => {1CB530F1-F6B1-404D-BCE6-1959BF91F4A8}
*/
static VALUE
fole_s_create_guid(self)
VALUE self;
{
GUID guid;
HRESULT hr;
OLECHAR bstr[80];
int len = 0;
hr = CoCreateGuid(&guid);
if (FAILED(hr)) {
ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "failed to create GUID");
}
len = StringFromGUID2(&guid, bstr, sizeof(bstr)/sizeof(OLECHAR));
if (len == 0) {
rb_raise(rb_eRuntimeError, "failed to create GUID(buffer over)");
}
return ole_wc2vstr(bstr, FALSE);
}
/*
* Document-class: WIN32OLE
*
@ -6932,6 +6958,7 @@ Init_win32ole()
rb_define_singleton_method(cWIN32OLE, "ole_show_help", fole_s_show_help, -1);
rb_define_singleton_method(cWIN32OLE, "codepage", fole_s_get_code_page, 0);
rb_define_singleton_method(cWIN32OLE, "codepage=", fole_s_set_code_page, 1);
rb_define_singleton_method(cWIN32OLE, "create_guid", fole_s_create_guid, 0);
rb_define_method(cWIN32OLE, "invoke", fole_invoke, -1);
rb_define_method(cWIN32OLE, "[]", fole_getproperty, 1);