Click here to Skip to main content
16,017,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
long COPCData::WriteVariable(LPCTSTR VariableName, const VARIANT& Value, long TimeOut)
{
	long result;
	static BYTE parms[] =
		VTS_BSTR VTS_VARIANT VTS_I4;
	InvokeHelper(0x11, DISPATCH_METHOD, VT_I4, (void*)&result, parms,
		VariableName, &Value, TimeOut);
	return result;
}


struct tagVARIANT VARIANT;

struct tagVARIANT
    {
    union
        {
        struct __tagVARIANT
            {
            VARTYPE vt;
            WORD wReserved1;
            WORD wReserved2;
            WORD wReserved3;
            union
                {
                LONGLONG llVal;
                LONG lVal;
                BYTE bVal;
                SHORT iVal;
                FLOAT fltVal;
                DOUBLE dblVal;
                VARIANT_BOOL boolVal;
                _VARIANT_BOOL bool;
                SCODE scode;
                CY cyVal;
                DATE date;
                BSTR bstrVal;
                IUnknown *punkVal;
                IDispatch *pdispVal;
                SAFEARRAY *parray;
                BYTE *pbVal;
                SHORT *piVal;
                LONG *plVal;
                LONGLONG *pllVal;
                FLOAT *pfltVal;
                DOUBLE *pdblVal;
                VARIANT_BOOL *pboolVal;
                _VARIANT_BOOL *pbool;
                SCODE *pscode;
                CY *pcyVal;
                DATE *pdate;
                BSTR *pbstrVal;
                IUnknown **ppunkVal;
                IDispatch **ppdispVal;
                SAFEARRAY **pparray;
                VARIANT *pvarVal;
                PVOID byref;
                CHAR cVal;
                USHORT uiVal;
                ULONG ulVal;
                ULONGLONG ullVal;
                INT intVal;
                UINT uintVal;
                DECIMAL *pdecVal;
                CHAR *pcVal;
                USHORT *puiVal;
                ULONG *pulVal;
                ULONGLONG *pullVal;
                INT *pintVal;
                UINT *puintVal;
                struct __tagBRECORD
                    {
                    PVOID pvRecord;
                    IRecordInfo *pRecInfo;
                    }   __VARIANT_NAME_4;
                }   __VARIANT_NAME_3;
            }   __VARIANT_NAME_2;
        DECIMAL decVal;
        }   __VARIANT_NAME_1;
    } 


---------------------------------------------------------------------------------
I try to use the WriteVariable() function to send the value of v1 back to the OPC server. The value may be "111". Do anyone konw how to define v1 here and assign value "111" to v1? Many thx!

C++
XXX_OPCDataControl.WriteVariable("XX.XX.XX",v1,0);
Posted
Updated 14-Aug-11 23:10pm
v2

1 solution

C++
VARIANT v1;
v1.iVal = 111;
XXX_OPCDataControl.WriteVariable("XX.XX.XX", &v1, 0);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900