VARIANT CMUSHclientDoc::GetWorldIdList() 
{
  COleSafeArray sa;   // for list

  CMUSHclientDoc * pDoc;
  long iCount = 0;
  POSITION pos;

  // count number of worlds
  for (pos = App.m_pWorldDocTemplate->GetFirstDocPosition(); pos != NULL; iCount++)
    pDoc = (CMUSHclientDoc *) App.m_pWorldDocTemplate->GetNextDoc(pos);

  if (iCount) // cannot create empty array dimension
    {
    sa.CreateOneDim (VT_VARIANT, iCount);
  
    // put the worlds into the array
    for (iCount = 0, pos = App.m_pWorldDocTemplate->GetFirstDocPosition(); pos != NULL; iCount++)
      {
      pDoc = (CMUSHclientDoc *) App.m_pWorldDocTemplate->GetNextDoc(pos);

      // the array must be a bloody array of variants, or VBscript kicks up
      COleVariant v (pDoc->m_strWorldID);
      sa.PutElement (&iCount, &v);
      }      // end of looping through each world
    } // end of having at least one

	return sa.Detach ();
}   // end of CMUSHclientDoc::GetWorldIdList
// returns a new 7-element array of doubles containing Force and Torque measurements
int FTWrapper::GetForcesAndTorques(double output[7])
{
	if (status == ALL_READY) {
		// this array is used to create the COleSafeArray below
		// it is used to indicate that there are 7 elements in the first diemnsion
		DWORD numElements[] = {7};
		COleSafeArray voltages;
		// VT_R8 represents an 8-byte real, i.e. a double in C++
		// there is 1 dimension with a size of 'numElements[0]'
		voltages.Create(VT_R8, 1, numElements);

		double ft_voltages[7];
		int mDAQstatus = mDAQSys->ScanGauges(ft_voltages, false);
		long i;
		for(i=0;i<7;i++) {
			// COleSafeArrays use pass-by-reference methods to read or write
			voltages.PutElement(&i,&(ft_voltages[i]));
		}
		// this method uses the calibration matrix (and possibly temperature compensation)
		// to convert the 6 gauge readings into forces and torques
		COleSafeArray forces = GetActiveCalibration().ConvertToFT(voltages,"lb","in-lb");
		for (i=0; i<6; i++) {
			// COleSafeArrays use pass-by-reference methods to read or write
			forces.GetElement(&i,&(output[i]));
		}
		// copy the thermistor voltage over to the output for display
		output[6] = ft_voltages[6];
		return mDAQstatus;
	}
	else {
		return -2;
	}
}
/* Called when an instrument update occurs (i.e. LTP changes).
 * @param pInstr Instrument updated
 */
void CSubmitOrderDialog::CInstrNotifySink_Update(XTAPI::ITTInstrObj* pInstr)
{
	long index = 0L;
	_variant_t vData;  

	// extract an array containing all of our required fields.
	COleSafeArray* lpData = new COleSafeArray(pInstr->GetGet((LPCSTR)"Bid,Ask,Last,Change"));

	lpData->GetElement(&index, &vData);	
	m_BidPriceBox = CString(vData); 
	
	lpData->GetElement(&++index, &vData);	
	m_AskPriceBox = CString(vData); 
	
	lpData->GetElement(&++index, &vData);	
	m_LTPBox = CString(vData); 

	lpData->GetElement(&++index, &vData);	
	m_ChangeBox = CString(vData); 

	// Call after updating the AFX_DATA fields
	UpdateData(false);

	// delete the array
	delete lpData;
	lpData = NULL;
}
// return list of windows we have made
VARIANT CMUSHclientDoc::WindowList() 
{
  COleSafeArray sa;   // for array list

  long iCount = 0;
  
  // put the arrays into the array
  if (!m_MiniWindows.empty ())    // cannot create empty dimension
    {
    sa.CreateOneDim (VT_VARIANT, m_MiniWindows.size ());

    for (MiniWindowMapIterator it = m_MiniWindows.begin (); 
         it != m_MiniWindows.end ();
         it++)
           {
            // the array must be a bloody array of variants, or VBscript kicks up
            COleVariant v (it->first.c_str ());
            sa.PutElement (&iCount, &v);
            iCount++;
           }

    } // end of having at least one

	return sa.Detach ();
}    // end of CMUSHclientDoc::WindowList
VARIANT CMUSHclientDoc::GetPluginList() 
{
  COleSafeArray sa;   // for variable list

  CString strVariableName;

  long iCount = 0;
  
  // put the plugins into the array
  if (!m_PluginList.empty ())    // cannot create empty dimension
    {
    sa.CreateOneDim (VT_VARIANT, m_PluginList.size ());

    for (PluginListIterator pit = m_PluginList.begin (); 
         pit != m_PluginList.end (); 
         ++pit)
      {
      CPlugin * p = *pit;

      // the array must be a bloody array of variants, or VBscript kicks up
      COleVariant v (p->m_strID);
      sa.PutElement (&iCount, &v);
      iCount++;
      }      // end of looping through each plugin
    } // end of having at least one

	return sa.Detach ();
}   // end of CMUSHclientDoc::GetPluginList
// specifies whether force/torque and voltages will be biased or not
void FTWrapper::Bias(bool newbias)
{
	bias = newbias;
	if (status & DAQ_READY) {
		if (bias == true) {
			// this array is used to create the COleSafeArray below
			// it is used to indicate that there are 7 elements in the first diemnsion
			DWORD numElements[] = {7};
			COleSafeArray voltages;
			// VT_R8 represents an 8-byte real, i.e. a double in C++
			// there is 1 dimension with a size of 'numElements[0]'
			voltages.Create(VT_R8, 1, numElements);

			mDAQSys->ScanGauges(biasVoltage, true);
//			if (mDAQstatus) {
				// bad bias!
//			}
			for(long i=0;i<7;i++) {
				// COleSafeArrays use pass-by-reference methods to read or write
				voltages.PutElement(&i,&(biasVoltage[i]));
			}
			// check the bits that indicate that the calibration file has been loaded and the DAQ is ready
			if (status == ALL_READY) {
				GetActiveCalibration().Bias(voltages);
			}
		}
		else {
			// check the bit that indicates that the calibration file has been loaded
			if (status & CALFILE_LOADED) {
				GetActiveCalibration().ClearBias();
			}
		}
	}
}
VARIANT CMUSHclientApp::GetGlobalOptionList() 
{
  COleSafeArray sa;   // for list
  long i, count = 0;

  // count them
  for (i = 0; GlobalOptionsTable [i].pName; i++)
    count++;

  for (i = 0; AlphaGlobalOptionsTable [i].pName; i++)
    count++;

  sa.CreateOneDim (VT_VARIANT, count);
  count = 0;

  // put the numeric option names into the array
  for (i = 0; GlobalOptionsTable [i].pName; i++)
    {
    // the array must be a bloody array of variants, or VBscript kicks up
    COleVariant v ((LPCTSTR) GlobalOptionsTable [i].pName);
    sa.PutElement (&count, &v);
    count++;
    }      // end of looping through each option

  // put the alpha option names into the array
  for (i = 0; AlphaGlobalOptionsTable [i].pName; i++)
    {
    // the array must be a bloody array of variants, or VBscript kicks up
    COleVariant v ((LPCTSTR) AlphaGlobalOptionsTable [i].pName);
    sa.PutElement (&count, &v);
    count++;
    }      // end of looping through each option

	return sa.Detach ();
}
VARIANT CMUSHclientDoc::GetTriggerList() 
{
  COleSafeArray sa;   // for wildcard list

  CString strTriggerName;
  CTrigger * trigger_item;
  long iCount = 0;
  POSITION pos;

  iCount = GetTriggerMap ().GetCount ();

  if (iCount) // cannot create empty array dimension
    {
    sa.CreateOneDim (VT_VARIANT, iCount);
  
    for (iCount = 0, pos = GetTriggerMap ().GetStartPosition(); pos; iCount++)
      {
      GetTriggerMap ().GetNextAssoc (pos, strTriggerName, trigger_item);

      // the array must be a bloody array of variants, or VBscript kicks up
      COleVariant v (strTriggerName);
      sa.PutElement (&iCount, &v);
      }      // end of looping through each trigger
    } // end of having at least one

	return sa.Detach ();
}    // end of CMUSHclientDoc::GetTriggerList
Beispiel #9
0
HRESULT CHtmlCtrl::Navigate(LPCTSTR lpszURL, 
			    DWORD dwFlags /*= 0*/,
			    LPCTSTR lpszTargetFrameName /*= NULL*/,
			    LPCTSTR lpszHeaders /*= NULL*/, 
			    LPVOID lpvPostData /*= NULL*/,
			    DWORD dwPostDataLen /*= 0*/)
{
    CString strURL(lpszURL);
    BSTR bstrURL = strURL.AllocSysString();

    COleSafeArray vPostData;
    if (lpvPostData != NULL)
    {
        if (dwPostDataLen == 0)
            dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);

        vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
    }

    return m_pBrowser->Navigate(bstrURL,
        COleVariant((long) dwFlags, VT_I4),
        COleVariant(lpszTargetFrameName, VT_BSTR),
        vPostData,
        COleVariant(lpszHeaders, VT_BSTR));
}
/* Called when an instrument is located after calling m_pInstrObj->Open()
 * @param pInstr Instrument located
 */
void CSubmitOrderDialog::CInstrNotifySink_Found(XTAPI::ITTInstrObj* pInstr)
{		
	m_StatusBar = (LPCSTR)"Instrument found.";
	
	// Populate the UI with the instrument information.
	m_ExchangeBox = (LPCSTR)pInstr->Exchange;
	m_ProductBox =(LPCSTR)pInstr->Product;
	m_ContractBox = (LPCSTR)pInstr->Contract;
	m_ProdTypeBox = (LPCSTR)pInstr->ProdType;

	// Create a TTOrderProfile to query for the Customer list
	XTAPI::ITTOrderProfilePtr orderProfile;
	orderProfile.CreateInstance(__uuidof(XTAPI::TTOrderProfile));

	// Populate the Customer ComboBox
	COleSafeArray* lpCustomers = new COleSafeArray(orderProfile->Customers);

	BSTR customer;  
	for (long i = 0L; i < (long)lpCustomers->GetOneDimSize(); i++)
	{
		lpCustomers->GetElement(&i, &customer);	
		m_CustomerCombo.AddString(CString(customer));
	}

	// Release TTOrderProfile
	orderProfile = NULL;

	// delete the array
	delete lpCustomers;
	lpCustomers = NULL;

	// select the first customer in the list.
	m_CustomerCombo.SetCurSel(0);

	// Create the TTOrderSet
	if (SUCCEEDED(m_pOrderSet.CreateInstance(__uuidof(XTAPI::TTOrderSet))))
	{	
		// Set NetLimits to false.
		m_pOrderSet->Set("NetLimits",0L);

		// Open the TTOrderSet to allow orders to be placed.
        m_pOrderSet->Open(true);
	}

	// Enable the controls on the form
	m_PriceControl.EnableWindow(true);
	m_QuantityControl.EnableWindow(true);
	m_StopPriceControl.EnableWindow(true);
	m_CustomerCombo.EnableWindow(true);
	m_OrderTypeCombo.EnableWindow(true);
	m_BuyButton.EnableWindow(true);
	m_SellButton.EnableWindow(true);

	// Call after updating the AFX_DATA fields
	UpdateData(false);
}
Beispiel #11
0
int mesage_AddFieldBinary(lua_State* L) {
	CMessage* msg = cmessage_arg(L, "mesage_AddFieldBinary");
	CString fldName = luaL_checkstring(L, 2);
	CString path = luaL_checkstring(L, 3); 
	int err;
	char *description;

	int charsLen = ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), NULL, 0);
	std::wstring characters(charsLen, '\0');
	::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), &characters[0], charsLen);

	int pf;
	char *b = NULL;
	err = _wsopen_s(&pf, characters.c_str(), _O_BINARY | _O_RDONLY, _SH_DENYWR, _S_IREAD);
	if (err) {
		description = "Open File error";
		goto err;
	}

	DWORD l = _filelength(pf);

	b = new char[l];


	if (l != _read(pf, b, l)) {
		err = -1;
		description = "Read File error";
		goto err;
	}
	err = _close(pf);
	if (err) {
		description = "Close File error";
		goto err;
	}
	{
		COleSafeArray arr;
		arr.Create(VT_UI1, 1, &l);

		for (DWORD i = 0; i < l; i++) {

			arr.PutElement((long*)&i, &b[i]);
		}

		msg->AddDatum(fldName, arr);
	}

err:
	if (b)
		delete []b;
	lua_pushinteger(L, err);
	if (err)
		lua_pushstring(L, description);
	else
		lua_pushinteger(L, l);
	return 2;
}
void __declspec(dllexport) __stdcall FillLocalArray(SequenceContext *seqContext,  short *errorOccurred,  long *errorCode,  char errorMsg[1024])
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    double *        numArray = NULL;
    unsigned int    numElements;
    double          numCycles = 2.0;
    PropertyObjectPtr   seqContextPOPtr;

    TRY
        // Set sequence context as a property object
    seqContextPOPtr = seqContext->AsPropertyObject();
   
        // The following code shows how to accesses properties via the ActiveX Automation API
    if (seqContextPOPtr->Exists("Locals.NumericArray",0)) 
        {
            // Create a Safe Array from the VARIANT which contains a
            // copy of the Locals.NumericArray. 
        COleSafeArray safeArray;
        safeArray.Attach(seqContextPOPtr->GetValVariant("Locals.NumericArray",0));
    
            // Check the size of the array of data - assuming 1D array  
        numElements = safeArray.GetOneDimSize();

            // Lock array for data access and get a pointer to the data.
            // (assuming it's an array of doubles)
        safeArray.AccessData((void**)&numArray);
        

            // Create sine pattern
        for (unsigned int i=0; i<numElements; i++)
            numArray[i] = sin((2*3.14) * i *numCycles/ numElements);

            // unlock array 
        safeArray.UnaccessData();

            // Set the value of the property the lookupString parameter specifies with a variant.  
            // Use this method to set the value of an entire array at once.                         
        seqContextPOPtr->SetValVariant("Locals.NumericArray", 0, safeArray);

        }
    
    CATCH(COleDispatchException, e) 
        *errorOccurred = TRUE;
        _mbsnbcpy_s((unsigned char *)errorMsg, 1024, (unsigned char *)LPCTSTR(e->m_strDescription), 1024 - 1);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = e->m_scError;

    AND_CATCH(CMemoryException, e)
        *errorOccurred = TRUE;
        e->GetErrorMessage(errorMsg, 1024);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = TS_Err_OutOfMemory;

    END_CATCH 
}
void __declspec(dllexport) __stdcall GetStringArray(SequenceContext *seqContext, short *errorOccurred,  long *errorCode,  char errorMsg[1024])
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    CString         displayString;
    BSTR            bstrElement;
    PropertyObjectPtr   seqContextPOPtr;

    TRY
        // Set sequence context as a property object
    seqContextPOPtr = seqContext->AsPropertyObject();

        // The following code shows how to accesses properties via the ActiveX Automation API
    if (seqContextPOPtr->Exists("Locals.StringArray",0)) 
        {
            // Create a Safe Array from the VARIANT which contains a
            // copy of the Locals.NumericArray. 
        COleSafeArray safeArray;
        safeArray.Attach(seqContextPOPtr->GetValVariant("Locals.StringArray",0));

            // Check the size of the array of data - assuming 1D array  
        unsigned long numElements = safeArray.GetOneDimSize( );

            // Get each element of array - assuming type BSTR
        for (long i=0; i<(long)numElements; i++)
            {
            CString tempString;
            safeArray.GetElement(&i, &bstrElement);
            tempString = bstrElement;
            SysFreeString(bstrElement);
            displayString += tempString + "\n";
            }
            // Get main application window handle so MessageBox is modal
        HWND hwnd = (HWND)seqContext->Engine->GetAppMainHwnd();
        MessageBox(hwnd, displayString, "String Array from TestStand Local Variable", MB_OK);
        }

    CATCH(COleDispatchException, e) 
        *errorOccurred = TRUE;
        _mbsnbcpy_s((unsigned char *)errorMsg, 1024, (unsigned char *)LPCTSTR(e->m_strDescription), 1024 - 1);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = e->m_scError;

    AND_CATCH(CMemoryException, e)
        *errorOccurred = TRUE;
        e->GetErrorMessage(errorMsg, 1024);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = TS_Err_OutOfMemory;

    END_CATCH 
}
Beispiel #14
0
COleVariant CLispEng::ToOleVariant(CP p) {
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

#ifdef X_DEBUG
	static ofstream os("c:\\out\\lisp.log");
	Print(os, p);
	os << endl;
#endif
	COleVariant r;
	switch (Type(p)) {
	case TS_CONS:
		if (!p)
			r.vt = VT_NULL;
		else
			E_Error();
		break;
	case TS_FIXNUM:
		return COleVariant((long)AsNumber(p));
	case TS_BIGNUM:
		{
			__int64 n;
			if (!ToBigInteger(p).AsInt64(n))
				E_Error();
			return COleVariant((long)n); // only lower 32 bits
		}
	case TS_SYMBOL:
		if (p == V_T)
			return COleVariant(true);
		E_Error();
	case TS_ARRAY:
		if (StringP(p))
			return COleVariant(AsString(p));
		else if (VectorP(p))
		{
			CArrayValue *av = ToVector(p);
			COleSafeArray sa;
			size_t len = av->GetVectorLength();
			sa.CreateOneDim(VT_VARIANT, (DWORD)len);
			for (long i=0; i<(long)len; ++i) {
				COleVariant v = ToOleVariant(av->GetElement(i));
				sa.PutElement(&i, &v);
			}
			return sa;
		}
		E_Error();
	default:
		E_Error();
	}
	return r;
}
void __declspec(dllexport) __stdcall AccessLocalArray(SequenceContext *seqContext, short *errorOccurred, long *errorCode,  char errorMsg[1024])
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    double *        numArray = NULL;
    unsigned int    numElements;
    PropertyObjectPtr   seqContextPOPtr;

    TRY 
        // Set sequence context as a property object
    seqContextPOPtr = seqContext->AsPropertyObject();

        // The following code shows how to accesses properties via the ActiveX Automation API
    if (seqContextPOPtr->Exists("Locals.NumericArray",0)) 
        {
            // Create a Safe Array from the VARIANT which contains a
            // copy of the Locals.NumericArray. 
        COleSafeArray safeArray;
        safeArray.Attach(seqContextPOPtr->GetValVariant("Locals.NumericArray",0));

            // Check the size of the array of data - assuming 1D array  
        numElements = safeArray.GetOneDimSize( );

            // Lock array for data access and get a pointer to the data.
            // (assuming it's an array of doubles)
        safeArray.AccessData((void**)&numArray);

            // Display data using LabWindows/CVI library function   
        if (CVI_YGraphPopup(seqContext->EngineAsDispatch, "Data in Local Array", numArray, numElements) < 0)
            AfxThrowMemoryException();

            // unlock array 
        safeArray.UnaccessData();
        }

    CATCH(COleDispatchException, e) 
        *errorOccurred = TRUE;
        _mbsnbcpy_s((unsigned char *)errorMsg, 1024, (unsigned char *)LPCTSTR(e->m_strDescription), 1024 - 1);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = e->m_scError;

    AND_CATCH(CMemoryException, e)
        *errorOccurred = TRUE;
        e->GetErrorMessage(errorMsg, 1024);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = TS_Err_OutOfMemory;

    END_CATCH 
}
Beispiel #16
0
	void pre_load_sheet(CWorksheet &sheet, COleSafeArray &safe_array)
	{
        ///当前的操作区域  
        CRange excel_current_range;
        excel_current_range.AttachDispatch(sheet.get_Cells(), true);  

		CRange used_range = sheet.get_UsedRange();    

		VARIANT ret_ary = used_range.get_Value2();
		if (!(ret_ary.vt & VT_ARRAY)){
			return;
		}

		safe_array.Clear();
		safe_array.Attach(ret_ary); 
	}
Beispiel #17
0
	int get_cell_int(COleSafeArray &ole_safe_array, int row, int col)
	{
		COleVariant vResult ;
		int ret;

		//字符串
		long read_address[2];
		VARIANT val;
		read_address[0] = row;
		read_address[1] = col;
		ole_safe_array.GetElement(read_address, &val);
		vResult = val;

		//整数
		switch(vResult.vt)
		{
		case VT_INT:
			ret = vResult.intVal;
			break;

		case VT_R8:
			ret = (int)vResult.dblVal;
			break;

		default:
			ret = 0;
			break;
		}

		return ret;
	}
Beispiel #18
0
HRESULT CWebCtrl::Navigate(LPCTSTR lpszURL, DWORD dwFlags, LPCTSTR lpszTargetFrameName, LPCTSTR lpszHeaders, LPVOID lpvPostData, DWORD dwPostDataLen)
{
	if ( m_pBrowser == NULL ) return E_UNEXPECTED;

	CComBSTR bstrURL( lpszURL );

	COleSafeArray vPostData;
	if ( lpvPostData != NULL )
	{
		if ( dwPostDataLen == 0 ) dwPostDataLen = lstrlen( (LPCTSTR)lpvPostData );
		vPostData.CreateOneDim( VT_UI1, dwPostDataLen, lpvPostData );
	}

	return m_pBrowser->Navigate( bstrURL, COleVariant( (long) dwFlags, VT_I4 ),
		COleVariant( lpszTargetFrameName, VT_BSTR ), vPostData,
		COleVariant( lpszHeaders, VT_BSTR ) );
}
void CMainFrame::Sort(VARIANT* vArray)
{
   COleSafeArray sa;
   BSTR *pbstr;
   TCHAR buf[1024];
   LONG cElements, lLBound, lUBound;
  
   //needed for OLE2T macro below, include afxpriv.h
   USES_CONVERSION;

   // Type check VARIANT parameter. It should contain a BSTR array
   // passed by reference. The array must be passed by reference it is
   // an in-out-parameter.
   if (V_VT(vArray) != (VT_ARRAY | VT_BSTR))
   {
      AfxThrowOleDispatchException(1001, 
         _T("Type Mismatch in Parameter. Pass a string array by reference"));
   }

   // clears data in sa and copies the variant data into sa
   sa.Attach(*vArray);

   // Check that array is 1 dimensional
   if (sa.GetDim() != 1)
   {
      AfxThrowOleDispatchException(1002, 
         _T("Type Mismatch in Parameter. Pass a one-dimensional array"));
   }

   try 
   {
      // Get array bounds.
      sa.GetLBound(1, &lLBound);
      sa.GetUBound(1, &lUBound);

      // Get a pointer to the elements of the array
      // and increments the lock count on the array
      sa.AccessData((LPVOID*)&pbstr);

      //get no. of elements in array
      cElements = lUBound - lLBound + 1;
      for (int i = 0; i < cElements; i++)
      {
         //output the elements of the array
         _stprintf_s(buf, 1024, _T("[%s]\n"), OLE2T(pbstr[i]));
         OutputDebugString(buf);
      }
      
      //decrement lock count
      sa.UnaccessData();
   }
   catch (COleException *pEx)
   {
      AfxThrowOleDispatchException(1003, 
         _T("Unexpected Failure in FastSort method"));
      pEx->Delete();
   }
}
void __declspec(dllexport) __stdcall SetStringArray(SequenceContext *seqContext, short *errorOccurred, long *errorCode, char errorMsg[1024])
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    CString         tempBuffer;
    BSTR            tempBstr;
    PropertyObjectPtr   seqContextPOPtr;

    TRY
        // Set sequence context as a property object
    seqContextPOPtr = seqContext->AsPropertyObject();
   
        // Create a Safe Array of 3 elements of type BSTR
    COleSafeArray safeArray;
    DWORD   rgElements[1] = {3};
    safeArray.Create( VT_BSTR, 1, rgElements );
    
        // Put a string in each element of the safe array
    for (long i=0; i<3; i++)
        {
        tempBuffer.Format("String%d", i);
        tempBstr = tempBuffer.AllocSysString();
        safeArray.PutElement(&i, tempBstr);
        SysFreeString(tempBstr);
        }

        // Set the safe array to the TestStand local variable
    seqContextPOPtr->SetValVariant("Locals.StringArray", 0, safeArray);    
    
    CATCH(COleDispatchException, e) 
        *errorOccurred = TRUE;
        _mbsnbcpy_s((unsigned char *)errorMsg, 1024, (unsigned char *)LPCTSTR(e->m_strDescription), 1024 - 1);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = e->m_scError;

    AND_CATCH(CMemoryException, e)
        *errorOccurred = TRUE;
        e->GetErrorMessage(errorMsg, 1024);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = TS_Err_OutOfMemory;

    END_CATCH 
}
Beispiel #21
0
VARIANT CMUSHclientDoc::GetAlphaOptionList() 
{
  COleSafeArray sa;   // for list
  long i;

  // count them
  for (i = 0; AlphaOptionsTable [i].pName; i++)
    ;

  sa.CreateOneDim (VT_VARIANT, i);

  // put the alpha option names into the array
  for (i = 0; AlphaOptionsTable [i].pName; i++)
    {
    // the array must be a bloody array of variants, or VBscript kicks up
    COleVariant v (AlphaOptionsTable [i].pName);
    sa.PutElement (&i, &v);
    }      // end of looping through each option

	return sa.Detach ();
}
void read_data(void)
{
    COleSafeArray array;

    int col = 0;
    LONG liSamplesAvailable, liChannelHND;

    liChannelHND = g_TTLLive->GetFirstChannelHND();
    while( liChannelHND > -1 ) {

        if( col == 0 )printf("\n\rData ");

        liSamplesAvailable = g_TTLLive->SamplesAvailable[liChannelHND];

        if( liSamplesAvailable ) {
            array = g_TTLLive->ReadChannelDataVT(liChannelHND, liSamplesAvailable );
        }

        // If any samples available, we simply print out value of the first one
        array.GetUBound(1,&liSamplesAvailable );
        if( liSamplesAvailable ) {
            LONG liIndice = 0;
            FLOAT fData;

            array.GetElement(&liIndice,&fData);

            printf("%c:%6.3f, ",(char)('A'+liChannelHND), fData);

        } else {
            printf("%c:NO DATA, ",(char)('A'+liChannelHND));
        }

        col++;
        if( col >= 5)col = 0;

        liChannelHND = g_TTLLive->GetNextChannelHND();
    }
    printf("\n\r");
}
void FTWrapper::SetBiasVoltages(double biases[])
{
	long i;

	COleSafeArray safeBias; /*we do the SafeArray dance to pass
							the data through COM*/	
	DWORD numElements[] = {7};
	safeBias.Create(VT_R8, 1, numElements);

	bias = true;

	/*set the stored bias and set up the safearray to pass to COM*/
	for (i = 0; i < 7; i++)
	{
		biasVoltage[i] = biases[i];
		safeBias.PutElement(&i, &biases[i]);
	}
	
	if (status == ALL_READY) 
		GetActiveCalibration().Bias(safeBias);	
	
}
Beispiel #24
0
void CHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
	LPCTSTR lpszTargetFrameName /* = NULL */,
	LPCTSTR lpszHeaders /* = NULL */,
	LPVOID lpvPostData /* = NULL */, DWORD dwPostDataLen /* = 0 */)
{
	ASSERT(m_pBrowserApp != NULL);

	COleSafeArray vPostData;
	if (lpvPostData != NULL)
	{
		if (dwPostDataLen == 0)
			dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);

		vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
	}

	COleVariant vURL(lpszURL, VT_BSTR);
	COleVariant vHeaders(lpszHeaders, VT_BSTR);
	COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
	COleVariant vFlags((long) dwFlags, VT_I4);

	m_pBrowserApp->Navigate2(vURL,
		vFlags, vTargetFrameName, vPostData, vHeaders);
}
/* Private method which extracts information from the instrument object
 * and publishes it to the UI.
 * @param pInstr Instrument updated
 */
void CPriceUpdateManualDialog::ProcessPriceData(XTAPI::ITTInstrObj* pInstr)
{
	long index = 0L;
	_variant_t vData;  

	// extract an array containing all of our required fields.
	COleSafeArray* lpData = new COleSafeArray(pInstr->GetGet((LPCSTR)"Bid,BidQty,Ask,AskQty,Last,LastQty,~LastQty"));

	lpData->GetElement(&index, &vData);	
	m_BidBox = CString(vData); 
	
	lpData->GetElement(&++index, &vData);	
	m_BidQtyBox = CString(vData); 
	
	lpData->GetElement(&++index, &vData);	
	m_AskBox = CString(vData); 

	lpData->GetElement(&++index, &vData);	
	m_AskQtyBox = CString(vData); 

	lpData->GetElement(&++index, &vData);	
	m_LastBox = CString(vData); 

	lpData->GetElement(&++index, &vData);	
	m_LastQty = CString(vData); 

	lpData->GetElement(&++index, &vData);	
	m_LastQtyChange = CString(vData); 

	// Call after updating the AFX_DATA fields
	UpdateData(false);

	// delete the array
	delete lpData;
	lpData = NULL;
}
Beispiel #26
0
bool CMUSHclientDoc::MXP_StartTagScript  (const CString & strName, 
                     const CString & strArguments,
                     CArgumentList & ArgumentList)
  {

  // don't make it too easy to dummy up AFK replies
  if (strName == "afk")
    return false;

  if (!SendToAllPluginCallbacks (ON_PLUGIN_MXP_OPENTAG, 
                                CFormat ("%s,%s",
                                (LPCTSTR) strName,
                                (LPCTSTR) strArguments)
                                ), true)
      return true;    


  // see if main script wants to do anything
  if (m_dispidOnMXP_OpenTag == DISPID_UNKNOWN)
    return false;

  long nInvocationCount = 0;
  long iCount = ArgumentList.GetCount ();

  CString strType = "MXP open tag";
  CString strReason =  TFormat ("opening MXP tag %s", (LPCTSTR) strName);

  if (GetScriptEngine () && GetScriptEngine ()->IsLua ())
    {
    list<double> nparams;
    list<string> sparams;
    sparams.push_back ((LPCTSTR) strName);    // name of tag
    sparams.push_back ((LPCTSTR) strArguments);  // all arguments

    map <string, string> table;

    CArgument * pArgument;
    POSITION pos;

    // put the arguments into the table

    for (iCount = 0, pos = ArgumentList.GetHeadPosition (); pos; iCount++)
      {
      pArgument = ArgumentList.GetNext (pos);
      CString strName = pArgument->strName;

      // empty ones we will put there by position
      if (strName.IsEmpty ())
        strName = CFormat ("%i",
                      pArgument->iPosition);
      
      table [(LPCTSTR) strName] = pArgument->strValue;
      }      // end of looping through each argument

    bool result;
    GetScriptEngine ()->ExecuteLua (m_dispidOnMXP_OpenTag, 
                                   m_strOnMXP_OpenTag, 
                                   eWorldAction,
                                   strType, 
                                   strReason, 
                                   nparams,
                                   sparams, 
                                   nInvocationCount,
                                   NULL,
                                   &table,
                                   NULL,
                                   &result);
    return result;
    }   // end of Lua

  COleSafeArray sa;   // for wildcard list

  if (iCount) // cannot create empty array dimension
    {
    sa.CreateOneDim (VT_VARIANT, iCount);

    CArgument * pArgument;
    POSITION pos;

    // put the arguments into the array

    for (iCount = 0, pos = ArgumentList.GetHeadPosition (); pos; iCount++)
      {
      pArgument = ArgumentList.GetNext (pos);

      // the array must be a bloody array of variants, or VBscript kicks up
      COleVariant v;
      
      // empty ones we will put there by position
      if (pArgument->strName.IsEmpty ())
        v = CFormat ("%i=%s",
                      pArgument->iPosition,
                      (LPCTSTR) pArgument->strValue);
      else
        v = CFormat ("%s=%s",
                      (LPCTSTR) pArgument->strName,
                      (LPCTSTR) pArgument->strValue);
      sa.PutElement (&iCount, &v);
      }      // end of looping through each argument
    } // end of having at least one

  // WARNING - arguments should appear in REVERSE order to what the sub expects them!

  enum
    {
    eArgumentArray,
    eArguments,
    eTagName,
    eArgCount,     // this MUST be last
    };    

  COleVariant args [eArgCount];
  DISPPARAMS params = { args, NULL, eArgCount, 0 };

  args [eTagName] = strName;
  args [eArguments] = strArguments;
  args [eArgumentArray] = sa;

  COleVariant result;

  ExecuteScript (m_dispidOnMXP_OpenTag,  
                 m_strOnMXP_OpenTag,
                 eWorldAction,
                 strType, 
                 strReason,
                 params, 
                 nInvocationCount,
                 &result); 

  // if the function returns a non-zero result, don't go ahead
  if (result.vt != VT_EMPTY)
    {
    result.ChangeType (VT_I4);  // make a long
    if (result.vt == VT_I4)   // conversion successful
      if (result.lVal)        // return if non-zero
        return true;
    }

  return false;
  } // end of CMUSHclientDoc::MXP_StartTagScript 
void __declspec(dllexport) __stdcall Access2DArray(SequenceContext *seqContext,  short *errorOccurred, long *errorCode, char errorMsg[1024])
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    double *        numArray = NULL;
    long            firstDimSize, secondDimSize, numberDimensions;
    BOUNDSELEMENT   *pBounds = NULL;
    PropertyObjectPtr   seqContextPOPtr;

    TRY
        // Set sequence context as a property object
    seqContextPOPtr = seqContext->AsPropertyObject();

    if (seqContextPOPtr->Exists("Locals.Array2D", 0)) 
        {
            // Create a Safe Array from the VARIANT which contains a
            // copy of the Locals.NumericArray. 
        COleSafeArray safeArray;
        safeArray.Attach(seqContextPOPtr->GetValVariant("Locals.Array2D",0));

            // Lock array for data access and get a pointer to the data.
            // (assuming it's an array of doubles)
        safeArray.AccessData((void**)&numArray);

            // Get number of dimensions of safearray
        numberDimensions = safeArray.GetDim();

            // Allocate data to hold dimension sizes
        pBounds = (BOUNDSELEMENT*)malloc(numberDimensions * sizeof(BOUNDSELEMENT));
        if (pBounds == NULL)
            AfxThrowMemoryException();
        
            // Get dimension sizes
        for (long i = 0; i<numberDimensions; i++)
            {
            safeArray.GetLBound(i+1, &pBounds[i].lowerBound);
            safeArray.GetUBound(i+1, &pBounds[i].upperBound);
            }

        if (numberDimensions == 2)  // 2-D array only
            {
            firstDimSize = pBounds[0].upperBound - pBounds[0].lowerBound + 1;
            secondDimSize = pBounds[1].upperBound - pBounds[1].lowerBound + 1;              

                // Display data using LabWindows/CVI library function   
                // Remove comments to display waveforms
            
				if (CVI_YGraphPopup(seqContext->EngineAsDispatch, "Data in Local Array 1", &numArray[0*secondDimSize], secondDimSize) < 0)
                    AfxThrowMemoryException();
                if (CVI_YGraphPopup(seqContext->EngineAsDispatch, "Data in Local Array 2", &numArray[1*secondDimSize], secondDimSize) < 0)
                    AfxThrowMemoryException();
            
            }

        free(pBounds);

            // unlock array 
        safeArray.UnaccessData();
        }

    CATCH(COleDispatchException, e) 
        *errorOccurred = TRUE;
        _mbsnbcpy_s((unsigned char *)errorMsg, 1024, (unsigned char *)LPCTSTR(e->m_strDescription), 1024 - 1);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = e->m_scError;

    AND_CATCH(CMemoryException, e)
        if (pBounds)
            free(pBounds);
        *errorOccurred = TRUE;
        e->GetErrorMessage(errorMsg, 1024);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = TS_Err_OutOfMemory;

    END_CATCH 
}
void __declspec(dllexport) __stdcall Create2DArray(SequenceContext *seqContext, short *errorOccurred, long *errorCode, char errorMsg[1024])
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    double          *array2D;
    DWORD   rgElements[2] = {2,100};
    PropertyObjectPtr   seqContextPOPtr;

    TRY
        // Set sequence context as a property object
    seqContextPOPtr = seqContext->AsPropertyObject();

        // To dynamically create variables, you would normally use the InsertIfMissing 
        // Property Option.  In TestStand 1.0 and 1.0.1, the InsertIfMissing option does 
        // not work with arrays.
        // This example demonstrates how to create an array using NewSubProperty
    seqContextPOPtr->NewSubProperty ("Locals.Array2D", PropValType_Number, TRUE, "", 0);

        // You do not need to do a SetDimension as SetValVariant 
        // auto dimensions the property object to be atleast as big as the safe array
        //  property.SetDimensions ("Locals.Array2D", 0, "[0][0]", "[1][99]");
    
        // Create a Safe Array from the VARIANT which contains a
        // copy of the Locals.NumericArray. 
    COleSafeArray safeArray;
    
        // Create a Safe Array of the required size
    safeArray.Create( VT_R8,2, rgElements); 
                    
                                       
        // Lock array for data access and get a pointer to the data.
        // (assuming it's an array of doubles)         
    safeArray.AccessData((void**)&array2D);

        // Create sine pattern
    for (int i=0; i<100; i++)
        {
        array2D[i] = sin((2*3.14) * i / 100);
        array2D[i+100] = cos((2*3.14) * i / 100);
        }

        // unlock array 
    safeArray.UnaccessData();

        
        // Set the value of the property the lookupString parameter specifies with a variant.  
        // Use this method to set the value of an entire array at once.                         
    seqContextPOPtr->SetValVariant("Locals.Array2D", 0, safeArray);

    CATCH(COleDispatchException, e) 
        *errorOccurred = TRUE;
        _mbsnbcpy_s((unsigned char *)errorMsg, 1024, (unsigned char *)LPCTSTR(e->m_strDescription), 1024 - 1);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = e->m_scError;

    AND_CATCH(CMemoryException, e)
        *errorOccurred = TRUE;
        e->GetErrorMessage(errorMsg, 1024);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = TS_Err_OutOfMemory;

    END_CATCH
}
Beispiel #29
0
BOOL CraftView::OnInitDialog() 
{
	CTabPageSSL::OnInitDialog();
	
	UpdateData(false);

	COleSafeArray saRet;
	
	SAFEARRAYBOUND sab[2];
	CString csTemp;
	long index[2] = {0,0}; //a 2D graph needs a 2D array as index array
	BSTR bstr;
	index[0]=1;
	int x=1, max_x =0, i;
	

	for( i = 0; i < MAX_CRAFT; i++)
	{
		if(GetLoadedObjCount() == 0)
			break;

		if(GetObjCraftCount(i) > 0)
			max_x++;
	}
	m_ChartControl.SetRowCount(1);
	m_ChartControl.SetShowLegend(TRUE);
	//m_ChartControl.SetAllowSelections(false);

	sab[0].cElements =1;
	sab[1].cElements = max_x+1;//number of columns + 1 (because the first column is where we put 

	sab[0].lLbound = sab[1].lLbound = 1;	
	
	saRet.Create(VT_BSTR, 2, sab);
	
	m_ChartControl.SetColumnCount(max_x);
	m_ChartControl.SetColumnLabelCount(max_x);
	
	index[1]=1;
	csTemp = "Craftsmanship";
	bstr = csTemp.AllocSysString(); // Row label
	saRet.PutElement(index, bstr);

	for(i = 0; i < MAX_CRAFT; i++)
	{
		if(GetLoadedObjCount() == 0)
			break;

		if(GetObjCraftCount(i) > 0)
		{
			x++;
			index[1]=x;
			csTemp.Format("%f", GetObjCraftPercent(i));
			bstr = csTemp.AllocSysString();
			saRet.PutElement(index, bstr);
			::SysFreeString(bstr);
		}
	}
	
	if(GetLoadedObjCount() >  0)
		m_ChartControl.SetChartData(saRet.Detach());
	
	x = 1;
	for(i = 0; i< MAX_CRAFT; i++)
	{
		if(GetLoadedObjCount() == 0)
			break;
		if(GetObjCraftCount(i) > 0)
		{
			m_ChartControl.SetColumn(x);
			m_ChartControl.SetColumnLabel(craftsmanship[i]);
			x++;
		}
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
VARIANT CMUSHclientDoc::SpellCheck(LPCTSTR Text) 
{

const char sFunction [] = "spellcheck_string";

	VARIANT vaResult;
	VariantInit(&vaResult);

  if (!App.m_bSpellCheckOK)
    return vaResult;

set<string> errors;

  if (App.m_SpellChecker_Lua)
    {

    lua_settop(App.m_SpellChecker_Lua, 0);   // clear stack

    lua_getglobal (App.m_SpellChecker_Lua, sFunction);  
    if (!lua_isfunction (App.m_SpellChecker_Lua, -1))
      return vaResult;  // cannot spell check string

    lua_pushstring (App.m_SpellChecker_Lua, Text);  // string to be checked

    int narg = lua_gettop(App.m_SpellChecker_Lua) - 1;  // all but the function
    int error = CallLuaWithTraceBack (App.m_SpellChecker_Lua, narg, 1);
  
    if (error)
      {
      LuaError (App.m_SpellChecker_Lua, "Run-time error", sFunction, "world.SpellCheck", "", this);
      return vaResult;  // cannot spell check string - syntax error
      }  

    if (lua_isnumber (App.m_SpellChecker_Lua, -1))
      {
      SetUpVariantLong (vaResult, lua_tonumber (App.m_SpellChecker_Lua, -1));        // no errors
  	  return vaResult;
      }

    // must be table or else return bad result
    if (!lua_istable (App.m_SpellChecker_Lua, -1))
      return vaResult;  // cannot spell check string - syntax error

    // convert returned table into a set
    for (int i = 1; ; i++)
      {
      lua_rawgeti (App.m_SpellChecker_Lua, 1, i);   // get i'th item
      if (lua_isnil (App.m_SpellChecker_Lua, -1))
        break;    // first nil key, leave loop
      // to avoid crashes, ignore table items that are not strings
      if (lua_isstring (App.m_SpellChecker_Lua, -1))
         errors.insert (lua_tostring (App.m_SpellChecker_Lua, -1));
      lua_pop (App.m_SpellChecker_Lua, 1); // remove value
      } // end of looping through table

    // maybe didn't find any errors?
    if (errors.empty ())
      {
      SetUpVariantLong (vaResult, 0);        // no errors
  	  return vaResult;
      }

    // now make array of the errors
    COleSafeArray sa;   // for wildcard list

    sa.CreateOneDim (VT_VARIANT, errors.size ());

    long iCount = 0;

    for (set<string>::const_iterator it = errors.begin (); 
         it != errors.end (); it++, iCount++)
      {
      // the array must be a bloody array of variants, or VBscript kicks up
      COleVariant v (it->c_str ());
      sa.PutElement (&iCount, &v);
      }      // end of looping through each error

	  return sa.Detach ();
    }   // end custom spell check


return vaResult;

} // end of SpellCheck