DISPPARAMS dpNoArgs={NULL, NULL, 0, 0};
The VARIANT vResult;
OLECHAR FAR * szFunction;
BSTR bstrTemp;
IDispatch * pDispDocs;
IDispatch * pDispSel;
IDispatch * pDispActiveDoc;
//DISPIDs
DISPID dispid_Docs;
DISPID dispid_DocsAdd;
DISPID dispid_Sel;
DISPID dispid_TypeText;
DISPID dispid_TypePara;
DISPID dispid_ActiveDoc;
DISPID dispid_SaveAs;
DISPID dispid_Quit;
//* * * * * * * * * * * * * * * * * * * * Start Automation * * * * * * * * * * * * * * * * * * * * * * *
: : CoInitialize (NULL);
Clsids clsids;
CLSIDFromProgID (L Word "Application", & amp; Clsids);
IUnknown * pUnk;
Retrieves the hr=: : CoCreateInstance (clsids, NULL, CLSCTX_SERVER,
IID_IUnknown, (void * *) & amp; PUnk);
IDispatch * pDispApp;
Hr=pUnk - & gt; QueryInterface (IID_IDispatch, (void * *) & amp; PDispApp);
SzFunction=OLESTR (" Documents ");
Hr=pDispApp - & gt; GetIDsOfNames (IID_NULL, & amp; SzFunction, 1,
LOCALE_USER_DEFAULT, & amp; Dispid_Docs);
Hr=pDispApp - & gt; Invoke (dispid_Docs IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
& DpNoArgs, & amp; VResult, NULL, NULL);
PDispDocs=vResult. PdispVal;
SzFunction=OLESTR (" Add ");
Hr=pDispDocs - & gt; GetIDsOfNames (IID_NULL, & amp; SzFunction, 1,
LOCALE_USER_DEFAULT,
& Dispid_DocsAdd);
Hr=pDispDocs - & gt; Invoke (dispid_DocsAdd IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
& DpNoArgs, & amp; VResult, NULL, NULL);
SzFunction=OLESTR (" Selection ");
Hr=pDispApp - & gt; GetIDsOfNames (IID_NULL, & amp; SzFunction, 1,
LOCALE_USER_DEFAULT, & amp; Dispid_Sel);
Hr=pDispApp - & gt; Invoke (dispid_Sel IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET, & amp; DpNoArgs, & amp; VResult,
NULL, NULL);
PDispSel=vResult. PdispVal;
SzFunction=OLESTR (" TypeText ");
Hr=pDispSel - & gt; GetIDsOfNames (IID_NULL, & amp; SzFunction, 1,
LOCALE_USER_DEFAULT,
& Dispid_TypeText);
TypeParagraph szFunction=OLESTR (" ");
Hr=pDispSel - & gt; GetIDsOfNames (IID_NULL, & amp; SzFunction, 1,
LOCALE_USER_DEFAULT,
& Dispid_TypePara);
The VARIANT vArgsTypeText [1].
DISPPARAMS dpTypeText;
BstrTemp=: : SysAllocString (OLESTR (" One "));
VArgsTypeText [0]. N=VT_BSTR;
VArgsTypeText [0]. BstrVal=bstrTemp;
DpTypeText. CArgs=1;
DpTypeText. CNamedArgs=0;
DpTypeText. Rgvarg=vArgsTypeText;
Hr=pDispSel - & gt; Invoke (dispid_TypeText IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
& DpTypeText, NULL, NULL, NULL);
Hr=pDispSel - & gt; Invoke (dispid_TypePara IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
& DpNoArgs, NULL, NULL, NULL);
: : SysFreeString (bstrTemp);
BstrTemp=: : SysAllocString (OLESTR (" Two "));
Hr=pDispSel - & gt; Invoke (dispid_TypeText IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
& DpTypeText, NULL, NULL, NULL);
Hr=pDispSel - & gt; Invoke (dispid_TypePara IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
& DpNoArgs, NULL, NULL, NULL);
: : SysFreeString (bstrTemp);
BstrTemp=: : SysAllocString (OLESTR (" Three "));
Hr=pDispSel - & gt; Invoke (dispid_TypeText IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
& DpTypeText, NULL, NULL, NULL);
Hr=pDispSel - & gt; Invoke (dispid_TypePara IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
& DpNoArgs, NULL, NULL, NULL);
: : SysFreeString (bstrTemp);
ActiveDocument szFunction=OLESTR (" ");
Hr=pDispApp - & gt; GetIDsOfNames (IID_NULL, & amp; SzFunction, 1,
LOCALE_USER_DEFAULT,
& Dispid_ActiveDoc);
Hr=pDispApp - & gt; Invoke (dispid_ActiveDoc IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
& DpNoArgs, & amp; VResult, NULL, NULL);
PDispActiveDoc=vResult. PdispVal;
The VARIANT vArgsSaveAs [11].
DISPPARAMS dpSaveAs;
DpSaveAs. CArgs=11;
DpSaveAs. CNamedArgs=0;
DpSaveAs. Rgvarg=vArgsSaveAs;
BSTR bstrEmptyString;
BstrEmptyString=: : SysAllocString (OLESTR (" "));
The VARIANT vFalse;
VFalse. N=VT_BOOL;
VFalse. BoolVal=FALSE;
BstrTemp=: : SysAllocString (OLESTR (" c: \ \ doc. Doc "));
VArgsSaveAs [10]. N=VT_BSTR;
VArgsSaveAs [10]. BstrVal=bstrTemp;
VArgsSaveAs [9]. N=VT_I4;
VArgsSaveAs [9]. LVal=0;
VArgsSaveAs [8]=vFalse;
VArgsSaveAs [7]. N=VT_BSTR;
VArgsSaveAs [7]. BstrVal=bstrEmptyString;
VArgsSaveAs [6]. N=VT_BOOL;
VArgsSaveAs [6]. BoolVal=TRUE;
VArgsSaveAs [5]. N=VT_BSTR;
VArgsSaveAs [5]. BstrVal=bstrEmptyString;
VArgsSaveAs [4]=vFalse;
VArgsSaveAs [3]=vFalse;
VArgsSaveAs [2]=vFalse;
VArgsSaveAs [1]=vFalse;
VArgsSaveAs [0]=vFalse;
SzFunction=OLESTR (" SaveAs ");
Hr=pDispActiveDoc - & gt; GetIDsOfNames (IID_NULL, & amp; SzFunction, 1,
LOCALE_USER_DEFAULT,
& Dispid_SaveAs);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull