Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: SafeArray in VFP and ActiveX Sockets

83 views
Skip to first unread message

MikeA

unread,
Jan 16, 2010, 1:33:04 AM1/16/10
to

One of the things tech support on one of my eval socket ActiveX controls
said I need to pass a "safearray" to the socket string buffer. This is
something I think is in VB. I've tried createbinary with a string in VFP
and it does not work. Does anyone know how to pass a safearray to an
ActiveX control in VFP?

Mike


Christian Ehlscheid

unread,
Jan 18, 2010, 3:59:07 AM1/18/10
to
Hello Mike,

this might work:

LOCAL loSocket, loInterface, lcData
loSocket = CREATEBOBJECT('yoursocketactivex')
loInterface = GETINTERFACE(m.loSocket, 'ISomeInterface') && replace
ISomeInterface with the real interface name that contains the method you
want to call (lookup in Object Browser)
lcData = CREATEBINARY(yourData)
loInterface.TheMethod(lcData)

Regards
Christian

MikeA

unread,
Jan 19, 2010, 12:52:51 AM1/19/10
to
I'm not sure how to get the interface name from the object browser although
I did pull up the control in the browser and found the methods. I just
wasn't sure where to look. Either way, I don't think it's going to work
because according to the vendor the problem is internally the control is
expecting to see an array and when it sees a string with binary text in it
the control is doing some kind of conversion. I have to find a way to pass
it a SafeArray the same way VB would.

I would think VFP would have some way of accomplishing this.

Any ideas?

Thanks,
Mike

"Christian Ehlscheid" <c.ehl...@edv-ermtraud.de> wrote in message
news:u$QmaxBmK...@TK2MSFTNGP06.phx.gbl...

Christian Ehlscheid

unread,
Jan 20, 2010, 10:00:13 AM1/20/10
to
Hello Mike,

VFP actually does pass a safearray of type VT_UI1 when you pass a string
created with CREATEBINARY.
You could try to use the COMARRAY function ...

LOCAL loSocket, loInterface, lcData
loSocket = CREATEBOBJECT('yoursocketactivex')

COMARRAY(m.loSocket, 1000) && try a few combinations of parameter 2
lcData = CREATEBINARY(yourData)
...

For locating the interface in the object browser just select your DLL,
expand the "Interfaces" node on the left pane, select an interface and
expand the "Methods" node on the right pane, if your method is listed there
you've probably got the right interface (if there aren't interfaces which
contain equal methods).

Regards
Christian

MikeA

unread,
Jan 20, 2010, 11:22:16 PM1/20/10
to
If I wanted to send it as a Byte Array then would I send the socket a string
or how would I set up a byte array in VFP?

Thanks,
Mike

"Christian Ehlscheid" <c.ehl...@edv-ermtraud.de> wrote in message

news:uIvYgEem...@TK2MSFTNGP04.phx.gbl...

MikeA

unread,
Jan 21, 2010, 12:26:26 AM1/21/10
to
I'm sorry - I re-read your post and you said VFP sends a string as type byte
array. Is this the same as the Variant Visual Basic SafeArray structure?
Also, I'm not sure which would be recommended for teh COMARRAY setting. I
tried them all and they all failed.

Thanks,
Mike

"MikeA" <app...@appellsoftware.com> wrote in message
news:e1CdRFlm...@TK2MSFTNGP04.phx.gbl...

Christian Ehlscheid

unread,
Jan 21, 2010, 4:58:19 AM1/21/10
to
Hello Mike,

can you tell me the name of the ActiveX control your're evaluating?
Without having a look myself at the control I can only guess on the correct
setting or if it's possible at all.

Regards
Christian

MikeA

unread,
Jan 23, 2010, 7:03:23 PM1/23/10
to
I'm currently evaluating Catalyst.com socket control but I think all of them
have problems and are doing conversion internally after they receive the
data so I don't think there is much I can do. What is perplexing to me is
this: If I transfer from workstation to server and I transfer File1 to
File2 then they do not compare but if I do it a second time and transfer
File1 to File3 then they still do not compare and surprisingly File2 and
File3 do not compare either. This is most surprising because it's almost as
if there is a "randomness" in the data being sent.

Mike

"Christian Ehlscheid" <c.ehl...@edv-ermtraud.de> wrote in message

news:uJnadAom...@TK2MSFTNGP02.phx.gbl...

Christian Ehlscheid

unread,
Jan 25, 2010, 3:31:54 AM1/25/10
to
Hello Mike,

i've uploaded a working sample using the Microsoft Winsock Control @
http://vfp2c.dyndns.org/uploads/files/winsocktest.zip

> What is perplexing to me is this: If I transfer from workstation to
> server and I transfer File1 to File2 then they do not compare but if I do
> it a second time and transfer File1 to File3 then they still do not
> compare and surprisingly File2 and File3 do not compare either. This is
> most surprising because it's almost as if there is a "randomness" in the
> data being sent.

I've encountered the same problem. The problem is caused by
the event sequence of the DataArrival Event.
The _VFP.AutoYield property has to be set to .F. in the winsock server
application, otherwise VFP will ocassionally trigger the DataArrival Event
during the
processing of the DataArrival event itself.
This also explains why the data corruption is random.


Regards
Christian

MikeA

unread,
Jan 25, 2010, 4:09:49 AM1/25/10
to
I have the autoyield set to false. I'm curious if you have tested your
sample and does it work with any size file? I tried the winsock activeX
control and could not get it to work on a form.

Mike

"Christian Ehlscheid" <c.ehl...@edv-ermtraud.de> wrote in message

news:uuS2yiZn...@TK2MSFTNGP04.phx.gbl...

Christian Ehlscheid

unread,
Jan 25, 2010, 4:27:08 AM1/25/10
to
Hello Mike,

I've tested it with a ~700MB avi file, i'm sure it'll work with every other
file too.

Christian

MikeA

unread,
Jan 25, 2010, 5:39:53 AM1/25/10
to
Do you have any idea why I might be getting corrupted data when I've tried
it with my code in a form?

Thanks,
Mike

"Christian Ehlscheid" <c.ehl...@edv-ermtraud.de> wrote in message

news:Ow9TqBan...@TK2MSFTNGP05.phx.gbl...

Christian Ehlscheid

unread,
Jan 25, 2010, 1:10:15 PM1/25/10
to
Hello Mike,

i've updated the sample @
http://vfp2c.dyndns.org/uploads/files/winsocktest.zip

now also contains vcx based winsock wrappers hosted in a form.

The one thing besides _VFP.AutoYield that is critical to receive binary
data is the code in the DataArrival Event of the server socket, one has
to call the GetData method of the winsock ocx like this:

#DEFINE vbArray 8192
#DEFINE vbByte 17
LOCAL lcData
lcData = '' && initialize to plain string
theSocket.GetData(@m.lcData, vbArray + vbByte)

Christian

MikeA

unread,
Jan 25, 2010, 8:55:37 PM1/25/10
to
I can't recall how I did it as I'll have to pull my archives but I have a
few questions/comments:

1. I'm wondering if this will work equally well in VFP 6/sp3 because I
noticed some commands are not supported but I did test your code in VFP 9
and it works.

2. I'm wondering if it matters if I don't put the m.lcData and just lcData
as that should also assume memory variables (I'm just trying to figure out
why my code did not work.

3. (and most important) I'm trying to figure out how to do this with the
Mabry Socket control. Also, I tried it before with winsock and I was
getting corruptions with both the mabry socket as well as the winsock but
when I compare the winsock code (mine and yours) I'm quite certain I'll
figure it out for winsock. I just don't know why the mabry socket is not
working. I can't recall if I used the second parameter with GetData but
I'll check my archives on that.

I really appreciate all the help you are providing me on this.

Thanks,
Mike

"Christian Ehlscheid" <chri...@vfp2c.com> wrote in message
news:OWQOimen...@TK2MSFTNGP06.phx.gbl...

MikeA

unread,
Jan 26, 2010, 3:57:02 AM1/26/10
to
Well - I've narrowed down the problem of the corrupted data. It seems to be
on the server side when I compile in VFP 6/SP3. Why does it work in VFP 9
with winsock and not VFP 6/sp3 on the server side? Any ideas of what I
might be able to do to make it work? Perhaps a third party socket control
or maybe another way to GetData(@m.lcData, vbArray + vbByte). Actually, I'm
thinking it seems to corrupt data in VFP 6 with GetData. Is the ComArray
defaults different in VFP 9 and maybe I can set them in 6? Any ideas?

Thanks,
Mike

"MikeA" <app...@appellsoftware.com> wrote in message

news:u6bv8qin...@TK2MSFTNGP05.phx.gbl...

MikeA

unread,
Jan 26, 2010, 4:03:17 AM1/26/10
to
Now I'm thinking it can't have to do with ComArray because the problem in
VFP 6 seems to be when receiving the data and not when sending. Any ideas as
to how to approach this?

Thanks,
Mike

"MikeA" <app...@appellsoftware.com> wrote in message

news:%23pj6BWm...@TK2MSFTNGP02.phx.gbl...

ED

unread,
Jan 27, 2010, 1:25:08 AM1/27/10
to
In Christian's code snip:
theSocket.GetData(@m.lcData, vbArray + vbByte)

I'm assuming theSocket is the winsock control, so you may want to try
theSocket.OBJECT.GetData(@m.lcData, vbArray + vbByte)

Using .OBJECT solves many problems when I use non-VFP controls. It may help
in VFP 6.
I suggest adding it to all calls to non-VFP methods of theSocket and
testing.

ED.


"MikeA" <app...@appellsoftware.com> wrote in message

news:%23uGDhZm...@TK2MSFTNGP05.phx.gbl...

MikeA

unread,
Jan 27, 2010, 1:05:00 PM1/27/10
to
Ed - thank you for your suggestion however I did already try that. In
general, one should only need to prefix it with .object when calling a
method that is also an event and since GetData is not an event it is not
necessary to prefix it but I did try that. Something else is going on and I
really want to try and make this work in VFP 6 if I can. Otherwise, it
means converting to 9 and that can be a real pain for a lot of my clients
because it means going to many workstations and having to give temporary
admin rights to install the VFP 9 dlls, etc. So, I'd like to avoid it for
now if possible. I keep thinking that this should work in 6/sp3 and I do
not know what is wrong. All I know is the test code for the client form
works if I send data to the server form when the server form is compiled in
vfp 9. So I've pretty much narrowed it down to getdata as the culprit but
I'm not sure what else to try.

Any ideas would be most appreciated.

Thanks,
Mike


"ED" <nos...@thankyou.com> wrote in message
news:exqM0lxn...@TK2MSFTNGP04.phx.gbl...

MikeA

unread,
Jan 28, 2010, 1:26:59 AM1/28/10
to
Any way to make this work in VFP 6/sp3? Why don't the sockets work?

Thanks,
Mike

"MikeA" <app...@appellsoftware.com> wrote in message

news:uGTx2s3n...@TK2MSFTNGP04.phx.gbl...

Christian Ehlscheid

unread,
Jan 28, 2010, 9:10:09 AM1/28/10
to
Hello Mike,

> Any way to make this work in VFP 6/sp3? Why don't the sockets work?

seems like VFP6 SP3 doesn't handle COM marshaling of the safearray datatype
correctly.

My FLL @ http://vfp2c.dyndns.org has an undocumented function called
"IDispatch_Invoke" which is able to call a method on a COM object and do
customizable marshaling of parameters,
it's not 100% finished so i'll have to have a look at it and make it work
with parameters passed by reference.

If you're interested I will finish it, so it at least will work with the
GetData method of the MS Winsock control.

Regards
Christian

MikeA

unread,
Jan 28, 2010, 5:02:16 PM1/28/10
to
Do you know if there is any way around this or maybe a socket that will work
with VFP 6/sp3? What I don't understand is why if I do a checksum and if
the checksums don't match and the do a resend eventually it will send good
data.

Mike

"Christian Ehlscheid" <c.ehl...@edv-ermtraud.de> wrote in message

news:uSEmwNCo...@TK2MSFTNGP04.phx.gbl...

Christian Ehlscheid

unread,
Jan 29, 2010, 7:33:04 AM1/29/10
to
Hello Mike,

No, i haven't used any other ActiveX socket controls besides the one
provided by Microsoft yet.
But if VFP 6/sp3 can't handle the safearray of byte datatype correctly
then you're out of luck since this is the only datatype in COM in general
which can transfer binary data safely.

Alternatively you can consider to use the winsock API directly, at least for
the server part.
A sample can be found here: http://www.news2news.com/vfp/?example=412

Regards
Christian


MikeA

unread,
Jan 29, 2010, 1:38:14 PM1/29/10
to
I'm confused by this link as I'm not understanding where the VFP code is.
There was a product for sale at marshallsoft.com that did work with a DLL
and a lot of DECLARE calls to the API but it seemed to be very slow to send
the files for some reason and I never got that into it.

I'm wondering where the source is for your link and how I access samples to
test this.

Thanks again,
Mike

"Christian Ehlscheid" <c.ehl...@edv-ermtraud.de> wrote in message

news:OLfaK8No...@TK2MSFTNGP02.phx.gbl...

MikeA

unread,
Feb 1, 2010, 12:55:27 AM2/1/10
to
Well - this continues to be an odd situation. It works in VFP 9 with the
winsock as per Christian's example and I got it to work with the Mabry
socket but strangely it only worked when I did NOT use the CreateBinary
function. When I use CreateBinary it does not work. Now, it would be such
a perfect world if I could get this to work in VFP 6/sp3. The Marshall
control works but that seems to be some kind of API calls to a dll and it
seems to be really slow. I'll play with that more and if that doesn't work
and and no one has any other ideas then I'm going to have to go the VFP 9
route.

What are the DLLs that must be installed and registered for VFP9?

Thanks again for all the help,
Mike

"MikeA" <app...@appellsoftware.com> wrote in message

news:u1oz3IRo...@TK2MSFTNGP06.phx.gbl...

0 new messages