From: Mike Williams on
On 6 Nov, 09:55, Scorpion_1982 <Scorpion_1...(a)o2.pl> wrote:

> Unfortunately I don't have the MSDN liblary
> for Visual Basic 6.0, My cd get "old" and my
> cd drive can't even read from it.

You don't swig rum out of barrels by any chance do you? And perhaps
have a wooden leg and a bird of some description perched on your
shoulder? [Just my little joke ;-)]

> I am looking all around the world an examples
> of UDT but I don't have anything useful

There is some VB documentation on the MSDN site somewhere, but
Microsoft seems to be steering all VB queries to one or other of their
new fangled VB.Net pages and I can't quite put my finger on it at the
moment. Perhaps someone else has a link? Mind you, since you've said
that you do not know anything about CopyMemory or any other WinAPI
stuff either then you would do well to buy yourself a decent "teach
yourself" book instead. I can't recommend any specific VB6 books
because I've never used any myself, but I can certainly recommend Dan
Appleman's "Visual Basic Programmers' Guide to the Win32 API" which
covers the API stuff very well. It's a bit out of date now and it
doesn't include any of the new GDI+ stuff, but it is still extremely
useful.

Anyway, here is some code that shows you how to do the reverse of what
we did yesterday (the equivalent of Get). I've included all of the
code that I originally posted (the "Put" stuff) as well because I've
modified it slightly so as to use a zero based array. The code does
not at the moment contain any error checking, and of course it is
written to deal only with the two specific UDTs that you are using
because I haven't got time at the moment to make it suitable for more
"general" use.

Paste the code into a VB Form containing two Command Buttons. Click
the first button (Command1) and it will perform the equivalent of a
"Put" from the two UDTs into bufString. Then click the second button
(Command2) and it will perform the equivalent of a "Get" from
bufString into two appropriate UDTs.

Mike

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Type Header
Typ As Long
Length As Long
End Type
Private Type Dane
Nick As String
IP As Long
End Type
Private bufString As String

Private Sub Command1_Click()
Dim buf() As Byte
Dim temp1 As Integer, temp2() As Byte
Dim struct_Header As Header
Dim struct_Dane As Dane
struct_Dane.Nick = "some nick"
struct_Dane.IP = 2
struct_Header.Typ = 1
struct_Header.Length = Len(struct_Dane)
' the above is your own stuff
ReDim buf(0 To 9)
CopyMemory buf(0), struct_Header.Typ, 8 ' the two Longs
temp1 = Len(struct_Dane.Nick)
CopyMemory buf(8), temp1, 2 ' the string length
temp2() = StrConv(struct_Dane.Nick, vbFromUnicode)
ReDim Preserve buf(0 To 9 + temp1 + 4)
CopyMemory buf(10), temp2(0), temp1 ' the string data
CopyMemory buf(10 + temp1), struct_Dane.IP, 4 ' the Long
bufString = StrConv(buf(), vbUnicode)
End Sub

Private Sub Command2_Click()
' Get the string created under Command1_Click
' code into two UDTs of the correct type.
Dim h As Header, d As Dane
Dim b() As Byte, temp1 As Long
' bufString would normally be the string you
' receive from Winsock
b() = StrConv(bufString, vbFromUnicode)
CopyMemory h.Typ, b(0), 8 ' the two Longs
CopyMemory temp1, b(8), 2 ' the string length
d.Nick = Mid$(bufString, 10 + 1, temp1)
CopyMemory d.IP, b(10 + temp1), 4
' print the result to test correct operation
Print h.Typ, h.Length
Print d.Nick, d.IP
End Sub



From: Scorpion_1982 on
I know VB 6.0 very well but I just doesn't know WinApi's fuctions
much.
I do not use any book as well because I have not seen any that would
have
learn me something I don't know yet, returning to WinApi... I am using
API-GUIDE
www.allapi.net

I am writing a program that lets to communication with such programs
as
"Gadu-Gadu" <- there everything is on the structures till this time I
was
using an operations on files and I was "hashing(?)" password using
liblary
..dll written in Borland C++, if there was something I could not figure
out
I was writting in c++ but this is really frustrating because I prefer
a code to be in one file, exactly just a protocol in one liblary.
I will give You a website about the protocol written in c, so You will
see for
youself what i want to write but in VB, here You have the website but
unfortunately in polish language,
so now You know why I can't just change the format, because I have to
fit to it, in c++ there is no problem
with sending/transfering structures through the WinSock, the
(controls[*.ocx/*.dll]) of vb is "a bit" poor, but anyway I do not
want to use it but
even though I needed the information how i can do this without an
operation on files.

Address: Protocol Gadu-Gadu
http://ekg.chmurka.net/docs/protocol.html

Thank You Mike Williams for the code and all Your help.

From: Mike Williams on
On 6 Nov, 14:33, Scorpion_1982 <Scorpion_1...(a)o2.pl> wrote:

> I will give You a website about the protocol
> written in c, so You will see for youself what
> i want to write but in VB, here You have the
> website but unfortunately in polish language

Ok. Thanks. But as far as C and Polish is concerned I'm afraid they're
both foreign languages to me :-)

> so now You know why I can't just change the format

That's okay. The code I posted shows you how to perform the equivalent
of both Put and Get on your specific UDTs, in your own specific
original format, without using a disk file. So, is that okay for you?
Or is there something else you need to know?

Mike




From: Randy Birch on
<AOL>me too</>

--

Randy
http://vbnet.mvps.org/


"Mike Williams" <gagamomo(a)yahoo.co.uk> wrote in message
news:1194300858.242190.91750(a)v3g2000hsg.googlegroups.com...
> On 5 Nov, 21:53, "Rick Rothstein \(MVP - VB\)"
> <rickNOSPAMn...(a)NOSPAMcomcast.net> wrote:
>
>> Here's wishing your wife a speedy recovery...
>
> Thanks Rick. I really appreciate it.
>
> Mike
>
>
>
>


From: Scorpion_1982 on
I have a few questions left.
1. How can I pass through the function my own type of data but in in
the
uniwersal way I mean, I want to be able to copy different types of
data.
2. How to check what kind of variables one after another a structure
contain without knowing the structure.
I am trying and I can't figure out, I was trying with function through
"Any"
but somehow VB does not support it and I don't know whats about in it.