Write data from safe array

'--------------------------------------------------------------------
' Visual Basic 6 - Write array
'--------------------------------------------------------------------
On Error GoTo ErrorHandler
	Dim DataToWrite(5) As Byte
	For i = 1 To 5
		DataToWrite(i) = i
	Next i
	Call FTSPCControl1.WriteArray(DataToWrite, 5)
Exit Sub

ErrorHandler:
	Dim err_code As Integer
	err_code = FTSPCControl1.GetLastError
	MsgBox "ErrorCode = " & CStr(err_code) & " - " & Err.Description, _
	vbCritical, "Error!"


/////////////////////////////////////////////////////////////////////
// C++ Example - Write array
/////////////////////////////////////////////////////////////////////
char *WriteBuffer = "Data to write";
VARIANT V;
V.vt = (VT_ARRAY|VT_UI1);
SAFEARRAY* psa;
psa = SafeArrayCreateVector(VT_UI1, 1, strlen(WriteBuffer));

if (psa != NULL)
{
	SafeArrayLock(psa);
	memcpy(psa->pvData, PVOID(WriteBuffer), strlen(WriteBuffer));
	SafeArrayUnlock(psa);
	V.parray = psa;
}

try
{
	m_SPCControl1.WriteArray(V, sizeof(WriteBuffer));
}
catch(COleDispatchException* E)
{
	MessageBox(E->m_strDescription, mbCaption, MB_OK | MB_ICONERROR);
}

if (psa != NULL)
{
	SafeArrayDestroy(psa);
}