ole_activex_initialize()
public
Initialize WIN32OLE object(ActiveX Control) by
calling IPersistMemory::InitNew.
Before calling OLE method, some kind of the ActiveX controls created with
MFC should be initialized by calling IPersistXXX::InitNew.
If and only if you recieved the exception “HRESULT error code: 0x8000ffff
catastrophic failure”, try this method before invoking any ole_method.
obj = WIN32OLE.new("ProgID_or_GUID_of_ActiveX_Control")
obj.ole_activex_initialize
obj.method(...)
Show source
/*
* call-seq:
* WIN32OLE#ole_activex_initialize() -> Qnil
*
* Initialize WIN32OLE object(ActiveX Control) by calling
* IPersistMemory::InitNew.
*
* Before calling OLE method, some kind of the ActiveX controls
* created with MFC should be initialized by calling
* IPersistXXX::InitNew.
*
* If and only if you recieved the exception "HRESULT error code:
* 0x8000ffff catastrophic failure", try this method before
* invoking any ole_method.
*
* obj = WIN32OLE.new("ProgID_or_GUID_of_ActiveX_Control")
* obj.ole_activex_initialize
* obj.method(...)
*
*/
static VALUE
fole_activex_initialize(self)
VALUE self;
{
struct oledata *pole;
IPersistMemory *pPersistMemory;
HRESULT hr = S_OK;
OLEData_Get_Struct(self, pole);
hr = pole->pDispatch->lpVtbl->QueryInterface(pole->pDispatch, &IID_IPersistMemory,
(void **)&pPersistMemory);
if (SUCCEEDED(hr)) {
hr = pPersistMemory->lpVtbl->InitNew(pPersistMemory);
OLE_RELEASE(pPersistMemory);
if (SUCCEEDED(hr)) {
return Qnil;
}
}
if (FAILED(hr)) {
ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "fail to initialize ActiveX control");
}
return Qnil;
}