使用OLE自动化打开现有的.odt文件

时间:2013-10-15 19:11:32

标签: visual-c++ com opendocument

我想使用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; 

感谢任何帮助。

0 个答案:

没有答案