How to call object methods passed as VARIANT argument 
Author Message
 How to call object methods passed as VARIANT argument

hi,

I am tring to Call  an object method.
My COM Object Method  takes an ADO Field Object as an agument and returns
it's value.

IDL declarations looks like this :
[id(3), helpstring("method GetFieldValue")] HRESULT
GetFieldValue([in]VARIANT* myFld,[in,optional] VARIANT mydefVal,[out,
retval]VARIANT* myRet);

Firt argument in this function will hold Field object .. ( test sample
created in VB ..)

----------------------------
STDMETHODIMP CDataAdaptor::GetFieldValue(VARIANT* myFld, VARIANT mydefVal,
VARIANT* myRet)
{
 AFX_MANAGE_STATE(AfxGetStaticModuleState())
 CallDispatch(myFld);
 return S_OK;

Quote:
}

------------------------------

last argument (return value) will hold the field value .. ( long,bstr ...)

in following function i try to call GetValue Property of ADO field object ..
but the functions fails ..at   GetIDsOfNames

------------------------------
HRESULT CDataAdaptor::CallDispatch(VARIANT* myObj)
{
try{
  IDispatchPtr myDisp=V_DISPATCH(myObj);
  //IDispatchPtr myDisp=myObj->pdispVal;
  //IDispatch* myDisp=myObj->pdispVal;

  HRESULT  hr;
  DISPPARAMS params;
  EXCEPINFO excepinfo;
  unsigned int uArgErr=-1;
  WCHAR *pName= L"GetValue";
  _variant_t result;
  DISPID dispid;

  hr=myDisp->GetIDsOfNames(IID_NULL,&pName,1,LOCALE_SYSTEM_DEFAULT,&dispid);

  if(!FAILED(hr))
  {
   params.cArgs = 0;
   params.rgvarg = NULL;
   params.cNamedArgs = 0;
   params.rgdispidNamedArgs = NULL;
   memset(&excepinfo, 0, sizeof(excepinfo));

   hr =myDisp->Invoke(
     dispid,
     IID_NULL,
     LOCALE_SYSTEM_DEFAULT,
     DISPATCH_PROPERTYGET,
     &params,
     &result,
     &excepinfo,
     &uArgErr);

   if(FAILED(hr))
   { ;; }
  }else{ ;;;}

   }catch(_com_error &e){
     _bstr_t bstrSource(e.Source());
     _bstr_t bstrDescription(e.Description());
     TRACE(_T("\tCode = %08lx\n"), e.Error());
     TRACE(_T("\tCode meaning = %s\n"), e.ErrorMessage());
     TRACE(_T("\tSource = %s\n"), (LPCTSTR) bstrSource);
     TRACE(_T("\tDescription = %s\n"), (LPCTSTR) bstrDescription);
     WriteLog(bstrDescription);
   }

 return S_OK;

Quote:
}

------------------------------

can anybody help making this work ..

thanks in advance ..



Sun, 03 Apr 2005 15:22:14 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. How to call object methods passed as VARIANT argument

2. How to call object methods passed as VARIANT argument

3. Variant arguments in methods of automation objects raise an exception

4. Variant arguments in methods of automation objects raise an exception

5. CString object passed as argument to its own Format() method

6. passing objects from VB as VARIANT to COM server object failing

7. passing objects from VB as VARIANT to COM server object failing

8. Unable to pass argument as VARIANT data

9. Unable to pass argument as VARIANT data

10. Testing a Variant Output argument in ATL Com object using VB client

11. Calling a COM call back object's method fails if it is in Windows 98

12. ADO Object Command and the method CreateParameter to add a variant in a Visual FoxPro database

 

 
Powered by phpBB® Forum Software