|
Subject:
|
sending a collection of UDTs
|
|
Posted By:
|
unholly_plugin
|
Post Date:
|
2/5/2004 11:00:10 AM
|
Hello,
I need help with sending a collection of my UDTs using the winsock control. i created a UDT with a few string types, integers and booleans
i have a function that returns a collection of my UDT.
i tried a few ways to send this collection with the winsock but the problem isnt the sending but recieving it is where my vb crash everytime!!!
it usually happens during the "CopyMemory" api function which tries to convert the variant which holds the data recieved by the "GetData" Method.
please help me, i have been battling this problem for weeks now and it is essential for my program to work that i succeed in this.
thank you.
|
|
Reply By:
|
gbianchi
|
Reply Date:
|
2/5/2004 11:08:35 AM
|
hi there..
maybe if you put some code we can help more??
Gonzalo Bianchi
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
2/5/2004 9:12:35 PM
|
Why are you using a Variant? Variant and CopyMemory are not friends...
You can read the data in an array of bytes, that are easier to manage:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
dim myUDT(something) dim bVal() as Byte redim bVal(myDataLength-1) .GetData bval, vbArray + vbByte, myDataLength CopyMemory myUDT(0), bval(0), myDataLength Just a thought, Marco
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
2/5/2004 9:19:12 PM
|
Sorry, I should have been more clear...
Dim myUDT(numberOfElements-1) as MyUdtType
the bVal array should be dimensioned as
dim myDataLength as Long myDataLength = numberOfElements * len(myUdt(0)) redim bVal(myDataLength - 1)
Just be careful with GetData, it is possible that not all data is available at that time and you have to do more calls.
quote: Originally posted by marcostraf
Why are you using a Variant? Variant and CopyMemory are not friends...
You can read the data in an array of bytes, that are easier to manage:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
dim myUDT(something) dim bVal() as Byte redim bVal(myDataLength-1) .GetData bval, vbArray + vbByte, myDataLength CopyMemory myUDT(0), bval(0), myDataLength Just a thought, Marco
|
|
Reply By:
|
unholly_plugin
|
Reply Date:
|
2/8/2004 7:30:02 AM
|
marcostraf,
first of all thanks for the tips.
but i have just one problem with your proposal: you used "NumberOfElements" but the number is not known and changes all the time. since my udt represents users that are logged on to my system and since this number can vary from 1 to n, theres a problem with getting the number of elements, or in my case users.
please help.
|
|
Reply By:
|
unholly_plugin
|
Reply Date:
|
2/9/2004 2:17:34 AM
|
i have another problem when i pass a udt with the winsock: when i send an integer it goes through the right way but when i try sending a string it comes out in the recieving end like this - "????" or just " ", or something like that.
does anyone know what could be the problem and what can i do with it?
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
2/9/2004 2:45:51 PM
|
In your original post you said that "I have a functions that returns a collection of my UDT". Now, this is strange because UDTs cannot be added in a collection. I just presumed that you know how many users you have... Can you give more info? What do you know in your code, from where you get the information and to where you have to send it?
Marco
quote: Originally posted by unholly_plugin
marcostraf,
first of all thanks for the tips.
but i have just one problem with your proposal: you used "NumberOfElements" but the number is not known and changes all the time. since my udt represents users that are logged on to my system and since this number can vary from 1 to n, theres a problem with getting the number of elements, or in my case users.
please help.
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
2/9/2004 2:50:19 PM
|
The VB String is in reality the COM BSTR object. Before sending it to a socket you have to change it to something more of a a low level (like an array of bytes or shorts, depending if you need wide characters)
Now my very bad question: why are you using a socket communication?
Marco
quote: Originally posted by unholly_plugin
i have another problem when i pass a udt with the winsock: when i send an integer it goes through the right way but when i try sending a string it comes out in the recieving end like this - "????" or just " ", or something like that.
does anyone know what could be the problem and what can i do with it?
|