How assign Variant type of data to safe array?
-
Hi, Am getting data from the serialport, when i call MComm->Getinput function to get the data from serial port, the data is stored in Variant type of data(result).I want to store this data in a safearray how to do that. VARIANT CMSComm::GetInput() { VARIANT result; InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL); unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY * psa; SAFEARRAYBOUND rgsabound[1]; VARIANT *pData; rgsabound[0].lLbound = 0; rgsabound[0].cElements = 10; psa = SafeArrayCreate(VT_BSTR, 1, rgsabound); var.vt=VT_ARRAY|VT_BSTR; SafeArrayAccessData(psa, (void HUGEP**)&pData); pData= result; // error:am not able to assign like this var.parray=psa; return var; } Thnaks
-
Hi, Am getting data from the serialport, when i call MComm->Getinput function to get the data from serial port, the data is stored in Variant type of data(result).I want to store this data in a safearray how to do that. VARIANT CMSComm::GetInput() { VARIANT result; InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL); unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY * psa; SAFEARRAYBOUND rgsabound[1]; VARIANT *pData; rgsabound[0].lLbound = 0; rgsabound[0].cElements = 10; psa = SafeArrayCreate(VT_BSTR, 1, rgsabound); var.vt=VT_ARRAY|VT_BSTR; SafeArrayAccessData(psa, (void HUGEP**)&pData); pData= result; // error:am not able to assign like this var.parray=psa; return var; } Thnaks
I'm no COM expert, but isn't there a way to get the Variant to collapse to a BSTR? Then store that in your array. Just split the problem in two, and you have solvable bits. Iain.
-
Hi, Am getting data from the serialport, when i call MComm->Getinput function to get the data from serial port, the data is stored in Variant type of data(result).I want to store this data in a safearray how to do that. VARIANT CMSComm::GetInput() { VARIANT result; InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL); unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY * psa; SAFEARRAYBOUND rgsabound[1]; VARIANT *pData; rgsabound[0].lLbound = 0; rgsabound[0].cElements = 10; psa = SafeArrayCreate(VT_BSTR, 1, rgsabound); var.vt=VT_ARRAY|VT_BSTR; SafeArrayAccessData(psa, (void HUGEP**)&pData); pData= result; // error:am not able to assign like this var.parray=psa; return var; } Thnaks
Your immediate problem would seem to be the need to use
*pData = result;
not that just changing that is going to make your code work. More generally if you're getting unparsed binary data in a VARIANT from a COM object isn't it already in a SafeArray? Check the type of the VARIANT and the contents of its array members. I suspect you'll find the VARIANT already is a SafeArray just disguised for COM/OLE Automation correctness. If not then I would do everything possible to keep the data away from SafeArrays which are code bloaty and awkward unless you're forced to interact with classic VB in which case they're also essential. Good luck.Nothing is exactly what it seems but everything with seems can be unpicked.