[Python-au] PythonCom Error - Solution

Christian Daldrup Christian.Daldrup at gmx.de
Wed Feb 9 18:44:57 CET 2005


Hello,

I found a way to solve my problem.

IDL File

---------------------------------------------------------------------------Code:


struct Param { 
      [helpstring("q")] double dTest; 
      [helpstring("ks")] VARIANT dArray; 
} Param; 
 

Dummy Method (C++) 
---------------------------------------------------------------------------
Code: 

STDMETHODIMP CTest::Dummy(Param *para, double *result) 
{ 

      VARIANT variantArray = para->dArray; 

      std::vector<double> localArray; 

      double dItem = 0.0; 
      long lVal[1]; 
      long i; 

      VARIANT varItem; 

      long lBound = 0; 
      long uBound = 0; 

      SafeArrayGetLBound(variantArray.parray,1,&lBound); 
      SafeArrayGetUBound(variantArray.parray,1,&uBound); 

      for (i=lBound;i <= uBound; i++) 
      { 
            lVal[0] = i; 
            SafeArrayGetElement(variantArray.parray, lVal, &varItem); 

            if (varItem.vt == VT_R8) 
                  localArray.push_back(varItem.dblVal); 
      } 

      *result = localArray[0]; 

      return S_OK; 
} 

PyCrust / Python Call

---------------------------------------------------------------------------Python-Code:


import win32com.client 
myCom = win32com.client.Dispatch("Com.Test") 
myRec = win32com.client.Record('Param', myCom) 
myRec.dArray = (1.0, 2.0, 3.0) 
result = myCom.Dummy(myRec) 
result 
1.0 
myRec.dArray = (4.5670, 2.0, 3.0) 
result = myCom.Dummy(myRec) 
result 
4.5670000000000002 

Cu 
Christian

-- 
Lassen Sie Ihren Gedanken freien Lauf... z.B. per FreeSMS
GMX bietet bis zu 100 FreeSMS/Monat: http://www.gmx.net/de/go/mail



More information about the python-au mailing list