Read data into safe array

'--------------------------------------------------------------------
' Visual Basic 6 - Read array
'--------------------------------------------------------------------
Private Sub FTSPCControl1_OnReceive(ByVal Count As Long)
On Error GoTo ErrorHandler
	Dim buf(1) As Byte
	ReadCnt = FTSPCControl1.ReadArray(buf, 1)

	If ReadCnt > 0 Then
		For i = 0 To ReadCnt - 1
			Text_Terminal.Text = Text_Terminal.Text + Chr(buf(i))
		Next i
	End If
Exit Sub

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


/////////////////////////////////////////////////////////////////////
// C++ Example - Read array
/////////////////////////////////////////////////////////////////////
void CSPCDemoDlg::OnReceiveFtspccontrol1(unsigned long Count)
{
	SAFEARRAY* psa;
	psa = SafeArrayCreateVector(VT_UI1, 1, Count);
	VARIANT V;
	V.vt = VT_ARRAY|VT_UI1;
	V.parray = psa;
	LONG ReadCnt;

	try 
	{
		ReadCnt = m_SPCControl1.ReadArray(&V, Count);
	}
	catch(COleDispatchException* E)
	{
		MessageBox(E->m_strDescription, mbCaption,
			MB_OK | MB_ICONERROR);
	}

	m_edit_Terminal.GetWindowTextW(tmp_edit_text);
	SafeArrayLock(V.parray);
	for (int i = 0; i < ReadCnt; i++)
	{
		PCHAR P = (PCHAR)V.parray->pvData + i;

		//Todo: add your code

	}
	SafeArrayUnlock(V.parray);
	SafeArrayDestroy(psa);
}