diff options
Diffstat (limited to 'ext/win32ole')
-rw-r--r-- | ext/win32ole/tests/testWIN32OLE.rb | 6 | ||||
-rw-r--r-- | ext/win32ole/win32ole.c | 29 |
2 files changed, 34 insertions, 1 deletions
diff --git a/ext/win32ole/tests/testWIN32OLE.rb b/ext/win32ole/tests/testWIN32OLE.rb index 185670c9fc..8c50c7666e 100644 --- a/ext/win32ole/tests/testWIN32OLE.rb +++ b/ext/win32ole/tests/testWIN32OLE.rb @@ -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 diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 2e6b49e9c3..7452e5b963 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -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); |