S
Steve Thresher
I've written an automation client in C++ that creates a document from a
template and then saves the document to disk. This is working as expected.
The problem I'm having is I need to replace some text before saving the
document and I cannot work out what all the argument types to
Selection.Find.Execute() should be. I am able to get the necessary dispatch
interfaces (Selection and Find), locate and Invoke the Execute method but
the return value is always DISP_E_EXCEPTION. I've tried retrieving exception
information by passing the address of an EXCEPINFO structure but all I get
back is the scode field set to DISP_E_TYPEMISMATCH. Can someone please tell
me what each argument type (VARIANT) should be. At the moment I have the
following:
VARIANT vFalse;
vFalse.vt=VT_BOOL;
vFalse.boolVal=FALSE;
// This is what VB passes when optional parameters are not specified
VARIANT vOptional;
vOptional.vt=VT_ERROR;
vOptional.scode=DISP_E_PARAMNOTFOUND;
// Set up the DISPPARAMS for the Execute method (15 arguments)
DISPPARAMS dpExecute;
VARIANT vArgsExecute[15];
dpExecute.cArgs=15;
dpExecute.cNamedArgs=0;
dpExecute.rgvarg=vArgsExecute;
vArgsExecute[0].vt = VT_BSTR;
vArgsExecute[0].bstrVal=bstrFind; // Find text
vArgsExecute[1] = vOptional; // Match case
vArgsExecute[2] = vOptional; // Match whole word
vArgsExecute[3] = vOptional; // Match wild cards
vArgsExecute[4] = vOptional; // Match sounds like
vArgsExecute[5] = vOptional; // Match all word forms
vArgsExecute[6] = vOptional; // Forward
vArgsExecute[7] = vOptional; // Wrap
vArgsExecute[8] = vOptional; // Format
vArgsExecute[9].vt = VT_BSTR;
vArgsExecute[9].bstrVal=bstrReplace; // Replace with
vArgsExecute[10].vt=VT_UI1;
vArgsExecute[10].bVal=2; // Replace (0=replace none, 1=replace one,
2=replace all)
vArgsExecute[11] = vOptional; // MatchKashida
vArgsExecute[12] = vOptional; // MatchDiacritics
vArgsExecute[13] = vOptional; // MatchAlefHamza
vArgsExecute[14] = vOptional; // MatchControl
// Invoke the Execute method
EXCEPINFO ex_info;
m_hrLast=pDispFind->Invoke(dispid_execute,IID_NULL,LOCALE_USER_DEFAULT,DISPA
TCH_METHOD,&dpExecute,&vResult,&ex_info,NULL);
Can somebody help me please as I'm slowly going mad!
template and then saves the document to disk. This is working as expected.
The problem I'm having is I need to replace some text before saving the
document and I cannot work out what all the argument types to
Selection.Find.Execute() should be. I am able to get the necessary dispatch
interfaces (Selection and Find), locate and Invoke the Execute method but
the return value is always DISP_E_EXCEPTION. I've tried retrieving exception
information by passing the address of an EXCEPINFO structure but all I get
back is the scode field set to DISP_E_TYPEMISMATCH. Can someone please tell
me what each argument type (VARIANT) should be. At the moment I have the
following:
VARIANT vFalse;
vFalse.vt=VT_BOOL;
vFalse.boolVal=FALSE;
// This is what VB passes when optional parameters are not specified
VARIANT vOptional;
vOptional.vt=VT_ERROR;
vOptional.scode=DISP_E_PARAMNOTFOUND;
// Set up the DISPPARAMS for the Execute method (15 arguments)
DISPPARAMS dpExecute;
VARIANT vArgsExecute[15];
dpExecute.cArgs=15;
dpExecute.cNamedArgs=0;
dpExecute.rgvarg=vArgsExecute;
vArgsExecute[0].vt = VT_BSTR;
vArgsExecute[0].bstrVal=bstrFind; // Find text
vArgsExecute[1] = vOptional; // Match case
vArgsExecute[2] = vOptional; // Match whole word
vArgsExecute[3] = vOptional; // Match wild cards
vArgsExecute[4] = vOptional; // Match sounds like
vArgsExecute[5] = vOptional; // Match all word forms
vArgsExecute[6] = vOptional; // Forward
vArgsExecute[7] = vOptional; // Wrap
vArgsExecute[8] = vOptional; // Format
vArgsExecute[9].vt = VT_BSTR;
vArgsExecute[9].bstrVal=bstrReplace; // Replace with
vArgsExecute[10].vt=VT_UI1;
vArgsExecute[10].bVal=2; // Replace (0=replace none, 1=replace one,
2=replace all)
vArgsExecute[11] = vOptional; // MatchKashida
vArgsExecute[12] = vOptional; // MatchDiacritics
vArgsExecute[13] = vOptional; // MatchAlefHamza
vArgsExecute[14] = vOptional; // MatchControl
// Invoke the Execute method
EXCEPINFO ex_info;
m_hrLast=pDispFind->Invoke(dispid_execute,IID_NULL,LOCALE_USER_DEFAULT,DISPA
TCH_METHOD,&dpExecute,&vResult,&ex_info,NULL);
Can somebody help me please as I'm slowly going mad!