VC++ Automation Word 2000 Error : Unable to Disable "Cntrl-C"

V

VM

Hi,

I am automating Word 2000 and I want to disable the "Ctrl C" keyboard functionality. (Using VBA I am successful in disabling

the "Ctrl-C" by doing this - "Application.FindKey(BuildKeyCode(wdKeyControl, wdKeyC)).Disable")

I am using the following C++ automation code which gives me the DISP_E_EXCEPTION error code on IDispatch::Invoke for

"Disable" method ("AutoWrap" function below is a wrapper around IDispatch::Invoke). Here is my C++ code:

parm1.vt = VT_I4;
parm1.lVal = wdKeyControl;//::SysAllocString(L"^");
parm2.vt = VT_I4;
parm2.lVal = wdKeyC;//::SysAllocString(L"c");
VariantClear(&result);
AutoWrap(DISPATCH_METHOD, &result, pWdApp, L"BuildKeyCode",2,parm2,parm1);

parm1.vt = VT_I4;
parm1.lVal = result.lVal;
VariantClear(&result);
AutoWrap(DISPATCH_PROPERTYGET , &result, pWdApp, L"FindKey", 1,parm1);

pWdKey = result.pdispVal;
AutoWrap(DISPATCH_METHOD, NULL,pWdKey , L"Disable", 0);

I will appreciate any help on this.

Thanks.
Vishal
----------------------

Here is the code for the AutoWrap Function if it helps:

HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp, LPOLESTR ptName, int cArgs...)
{
// Begin variable-argument list...
va_list marker;
va_start(marker, cArgs);

if(!pDisp) {
MessageBox(NULL, "NULL IDispatch passed to AutoWrap()", "Error", 0x10010);
_exit(0);
}

// Variables used...
DISPPARAMS dp = { NULL, NULL, 0, 0 };
DISPID dispidNamed = DISPID_PROPERTYPUT;
DISPID dispID;
HRESULT hr;
char buf[200];
char szName[200];
EXCEPINFO pExcepInfo;

// Convert down to ANSI
WideCharToMultiByte(CP_ACP, 0, ptName, -1, szName, 256, NULL, NULL);

// Get DISPID for name passed...
hr = pDisp->GetIDsOfNames(IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT, &dispID);
if(FAILED(hr)) {
sprintf(buf, "IDispatch::GetIDsOfNames(\"%s\") failed w/err 0x%08lx", szName, hr);
MessageBox(NULL, buf, "AutoWrap()", 0x10010);
//_exit(0);
return hr;
}

// Allocate memory for arguments...
VARIANT *pArgs = new VARIANT[cArgs+1];
ZeroMemory(pArgs, (cArgs+1)* sizeof (VARIANT));
// Extract arguments...
for(int i=0; i<cArgs; i++) {
pArgs = va_arg(marker, VARIANT);
}

// Build DISPPARAMS
dp.cArgs = cArgs;
dp.rgvarg = pArgs;

// Handle special-case for property-puts!
if(autoType & DISPATCH_PROPERTYPUT) {
dp.cNamedArgs = 1;
dp.rgdispidNamedArgs = &dispidNamed;
}

// Make the call!
hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, autoType, &dp, pvResult, &pExcepInfo, NULL);
switch(hr)
{
case S_OK:
break;
case DISP_E_BADPARAMCOUNT:
MessageBox(0,"1","",0);
break;
case DISP_E_BADVARTYPE:
MessageBox(0,"2","",0);
break;
case DISP_E_EXCEPTION:
MessageBox(0,"3","",0);
break;
case DISP_E_MEMBERNOTFOUND:
MessageBox(0,"4","",0);
break;
case DISP_E_NONAMEDARGS:
MessageBox(0,"5","",0);
break;
case DISP_E_OVERFLOW:
MessageBox(0,"6","",0);
break;
case DISP_E_PARAMNOTFOUND:
MessageBox(0,"7","",0);
break;
case DISP_E_TYPEMISMATCH:
MessageBox(0,"8","",0);
break;
case DISP_E_UNKNOWNINTERFACE:
MessageBox(0,"9","",0);
break;
case DISP_E_UNKNOWNLCID:
MessageBox(0,"10","",0);
break;
case DISP_E_PARAMNOTOPTIONAL:
MessageBox(0,"11","",0);
break;
default:
MessageBox(0,"Default","",0);
break;
}
if(FAILED(hr)) {
sprintf(buf, "IDispatch::Invoke(\"%s\"=%08lx) failed w/err 0x%08lx", szName, dispID, hr);
MessageBox(NULL, buf, "AutoWrap()", 0x10010);
//_exit(0);
return hr;
}
// End variable-argument section...
va_end(marker);

delete [] pArgs;

return hr;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top