0

我想使用 COM OLE 自动化打开 OpenDocument Text 一些文件。

IDispatch *pSm;  //XMultiServiceFactory
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pSm); 

_variant_t result; 
_variant_t param(TEXT("com.sun.star.frame.Desktop")); 
hr = AutoWrap(DISPATCH_METHOD, &result.GetVARIANT(), pSm, TEXT("createInstance"), 1, param);
IDispatch *pStardesktop = result;

_variant_t parm0(TEXT("private:factory/swriter")); 
_variant_t parm1(TEXT("_blank")); 
_variant_t parm2(0L);
_variant_t parm3;
parm3.vt = VT_ARRAY | VT_VARIANT;
parm3.parray = parm3.parray = NULL; 

param = TEXT("com.sun.star.reflection.CoreReflection");
hr = AutoWrap(DISPATCH_METHOD, &result.GetVARIANT(), pSm, TEXT("createInstance"), 1, param.GetVARIANT());
IDispatch *pCoreReflection = result;

_variant_t typeName(TEXT("com.sun.star.beans.PropertyValue"));
hr = AutoWrap(DISPATCH_METHOD, &result.GetVARIANT(), pCoreReflection, TEXT("forName"), 1, typeName.GetVARIANT());
IDispatch *pIdlClass = result;

_variant_t obj;
hr = AutoWrap(DISPATCH_METHOD, &result.GetVARIANT(), pIdlClass, TEXT("createObject"), 1, obj.GetVARIANT());
IDispatch *pValue = obj;
//Get Stuck here:
//after this call obj.vt = VT_EMPTY. Don't know how to create PropertyValue object
//and should it be stored in VARIANT?
//then, how to encapsulate those properties to parm3?

hr = AutoWrap(DISPATCH_METHOD, &result.GetVARIANT(), pStardesktop, TEXT("loadComponentFromURL"), 4, parm3.GetVARIANT(), parm2.GetVARIANT(), parm1.GetVARIANT(), parm0.GetVARIANT()); 
IDispatch *pDoc = result; 

任何帮助表示赞赏。

4

0 回答 0