ole_query_interface(p1)
public
Returns WIN32OLE object for a specific
dispatch or dual interface specified by iid.
ie = WIN32OLE.new('InternetExplorer.Application')
ie_web_app = ie.ole_query_interface('{0002DF05-0000-0000-C000-000000000046}')
static VALUE
fole_query_interface(VALUE self, VALUE str_iid)
{
HRESULT hr;
OLECHAR *pBuf;
IID iid;
struct oledata *pole = NULL;
IDispatch *pDispatch;
void *p;
pBuf = ole_vstr2wc(str_iid);
hr = CLSIDFromString(pBuf, &iid);
SysFreeString(pBuf);
if(FAILED(hr)) {
ole_raise(hr, eWIN32OLERuntimeError,
"invalid iid: `%s'",
StringValuePtr(str_iid));
}
pole = oledata_get_struct(self);
if(!pole->pDispatch) {
rb_raise(rb_eRuntimeError, "failed to get dispatch interface");
}
hr = pole->pDispatch->lpVtbl->QueryInterface(pole->pDispatch, &iid,
&p);
if(FAILED(hr)) {
ole_raise(hr, eWIN32OLEQueryInterfaceError,
"failed to get interface `%s'",
StringValuePtr(str_iid));
}
pDispatch = p;
return create_win32ole_object(cWIN32OLE, pDispatch, 0, 0);
}