Wiki Home

VFP with Dot NET


Namespace: VFP
A place for info on using VFP with DotNetOffsite link to http://gotdotnet.com

A good starting place is on Got Dotnet: http://gotdotnet.com/team/vfp
See also VFP Toolkit For DotNet
See also Net Extender For VFP
The challenge - transport VFP binary string data across a .Net Socket interface and reassemble the VFP string at the other end of the .Net Socket connection. Sockets are not native functionality in VFP but are well supported in .Net.

Data flows across .Net sockets encoded as a byte array. The VFP function CREATEBINARY() will create the necessary byte array. The problem is when you extract the data at the receiving end of the socket you need to convert this byte array back into a VFP binary string. It is the binary part that presents the challenge. In .Net a string is apparently by definition a limited set of ASCII characters substituting a '?' for characters beyond Hex 07.

Using Net Extender For VFP, the following code snippet works for converting the received byte array but it is very slow:
lcData = ''
lnBufferSize = 4096
loBytes = CLRCreateZeroBasedArray("system::byte", lnBufferSize)
* Setup and Read Socket Stream Into loBytes
FOR lnI = 1 TO lnBytesRead
lcData = lcData + CHR(loBytes.GetValue(lnI - 1))
ENDFOR

The very fast but not readily apparent way to recreate your VFP binary string is as follows:
lcData = ''
lnBufferSize = 4096
loBytes = CLRCreateZeroBasedArray("system::byte", lnBufferSize)
loConvert = CLRNewObject("System::Text::ASCIIEncoding", 'mscorlib.dll')
loEncode = loConvert.GetEncoding(1252)
* Setup and Read Socket Stream Into loBytes
lcHex = loEncode.GetBytes(loEncode.GetString(loBytes, 0, lnBytesRead))
lcData = lcData + CAST(lcHex AS M)
Category DotNet
( Topic last updated: 2009.03.11 11:11:24 PM )