static VALUE
fole_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE svr_name;
VALUE host;
VALUE others;
HRESULT hr;
CLSID clsid;
OLECHAR *pBuf;
IDispatch *pDispatch;
void *p;
rb_secure(4);
rb_call_super(0, 0);
rb_scan_args(argc, argv, "11*", &svr_name, &host, &others);
Check_SafeStr(svr_name);
if (rb_safe_level() > 0 && OBJ_TAINTED(svr_name)) {
rb_raise(rb_eSecurityError, "Insecure Object Creation - %s",
StringValuePtr(svr_name));
}
if (!NIL_P(host)) {
Check_SafeStr(host);
if (rb_safe_level() > 0 && OBJ_TAINTED(host)) {
rb_raise(rb_eSecurityError, "Insecure Object Creation - %s",
StringValuePtr(svr_name));
}
return ole_create_dcom(argc, argv, self);
}
/* get CLSID from OLE server name */
pBuf = ole_vstr2wc(svr_name);
hr = CLSIDFromProgID(pBuf, &clsid);
if(FAILED(hr)) {
hr = CLSIDFromString(pBuf, &clsid);
}
SysFreeString(pBuf);
if(FAILED(hr)) {
ole_raise(hr, eWIN32OLERuntimeError,
"unknown OLE server: `%s'",
StringValuePtr(svr_name));
}
/* get IDispatch interface */
hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
&IID_IDispatch, &p);
pDispatch = p;
if(FAILED(hr)) {
ole_raise(hr, eWIN32OLERuntimeError,
"failed to create WIN32OLE object from `%s'",
StringValuePtr(svr_name));
}
ole_set_member(self, pDispatch);
return self;
}