IDL and COM question, I get error Parameter not optional

  • Thread starter Thread starter HasGen
  • Start date Start date
H

HasGen

Guest
I have a ATL COM object

import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(0220a616-bff9-40ae-8bb5-03935836f1eb),
dual,
nonextensible,
pointer_default(unique)
]
interface IIDLTestObj : IDispatch
{
[helpstring("DoIt method."), helpcontext(0)]
HRESULT DoIt([in] VARIANT_BOOL Ex,
[in, defaultvalue(2)] long Mode,
[in, optional] VARIANT B,
[out, retval] long* Status);
};
[
uuid(eb1809cf-87d0-4ef3-8365-231d9afa8104),
version(1.0),
]
library IDLTestLib
{
importlib("stdole2.tlb");
[
uuid(44092e2c-6585-4c17-8daa-e63d3ffb3043)
]
coclass IDLTestObj
{
[default] interface IIDLTestObj;
};
};

import "shobjidl.idl";



and a user MFC dialog has two handlers


void CIDLTestUserDlg::OnBnClickedOk() // I get error Parameter not optional
{
CComPtr<IDispatch> pDisp;
HRESULT hr = pDisp.CoCreateInstance(L"IDLTest.IDLTestObj");
CComDispatchDriver d(pDisp);
CComVariant vArgs[3];
vArgs[0] = VARIANT_TRUE;
vArgs[1] = CComVariant(long(2));
vArgs[2] = vtMissing;
hr = d.InvokeN((LPCOLESTR)_bstr_t(L"DoIt"), &vArgs[0], 3);
if (FAILED(hr)) {
CComPtr<IErrorInfo> pIErrorInfo;
::GetErrorInfo(0, &pIErrorInfo);
_com_error error(hr, pIErrorInfo);
pIErrorInfo.Detach();
CString strError(L"DoIt : ");
strError += error.ErrorMessage();
MessageBox(strError);
}
}

void CIDLTestUserDlg::OnBnClickedButton1() // This works
{
CComVariant v = vtMissing;
IDLTestLib::IIDLTestObjPtr pTest;
HRESULT hr = pTest.CreateInstance(L"IDLTest.IDLTestObj");
long n = pTest->DoIt(VARIANT_TRUE, 2, v);

}


why do I get error Parameter not optional


on dispatch call?

Continue reading...
 
Back
Top