Distinct offers Network Monitor, the ONLY natural language Protocol Analyzer, ONC RPC for C++, .NET and Java, and IntelliTerm, the fastest Terminal Emulator for TN3270, TN5250 and VT420 on the market.

Conversion from Structure to String and from String to Structure

   Products   Downloads   Sales   Support   About us
  VIT



        
 
 

The Windows Sockets ActiveX control and the TCP Server ActiveX control in the Distinct Visual Internet Toolkit - 32 require that all data sent or received must be defined as a string. Other Visual Basic predefined data types and user defined data types cannot be sent or received. Instead, user defined data types (structures) must be converted (copied) into strings before sending them and strings must be converted (copied) into structures after receiving them.

To allow this conversion of structures to strings and strings to structures, Distinct Visual Internet Toolkit - 32 supplies the "DSTRCT32.DLL" library. The "T32-107 Disk 1" diskette contains this file in the \DSTRUCT subdirectory. Copy this file to the directory which contains the Distinct program files (ActiveX controls) on your hard drive. The CopyStruct function in "DSTRCT32.DLL" is used for the conversion and must be declared in a Visual Basic application as follows.

Declare Function CopyStruct Lib "DSTRCT32.DLL" (ByVal Dst As Any, ByVal Src As Any, ByVal Length As Long) As Integer.

For predefined data types, the above declaration is sufficient. The declaration has to be modified for user defined data types (structures). For each user defined structure, the CopyStruct function must be declared twice (each time under a different name) and both declarations must be aliased to the CopyStruct function. Each function declaration specifies the type of conversion (converting a structure to a string or converting a string to a structure).

For example, the following two declarations are necessary for the user defined structure MyStruct.

Declare Function CopyStruct1 Lib "DSTRCT32.DLL" Alias "CopyStruct" (ByVal Dst As Any, Src As MyStruct, ByVal Length As Long) As Integer
Declare Function CopyStruct2 Lib "DSTRCT32.DLL" Alias "CopyStruct" (Dst As MyStruct, ByVal Src As Any, ByVal Length As Long) As Integer

CopyStruct1 is an alias of the CopyStruct function to specifically copy MyStruct to a string. Similarly, CopyStruct2 is an alias of the CopyStruct function to specifically copy a string to MyStruct.

To Send a Structure

1. Convert the structure to a string using the CopyStruct function.

The Src parameter is the structure to copy.

The Dst parameter is the string.

The Length parameter is the exact number of bytes to copy from the Src parameter.

2. Assign the Dst parameter string to the Send property of the custom control.

To Receive a Structure

1. Assign the Receive property of the custom control to a string.

2. Convert the string to a structure using the CopyStruct function.

The Src parameter is the string to copy.

The Dst parameter is the structure.

The Length parameter is the exact number of bytes to copy from the Src parameter.

Note

The CopyStruct function can be used to copy any data type to a string and vice versa. The data type can be an Integer, a Long, a user defined structure or even another string. Aliases of the CopyStruct function are only required for user defined structures and data types.

Example

The following example describes the usage of the CopyStruct function:

Type MyStruct1 ' user defined type 1
CustNum As Long
CustName As String * 40
End Type
Type MyStruct2 ' user defined type 2
Index As Integer
Value As Long
End Type
' generic declaration
Declare Function CopyStruct Lib "DSTRCT32.DLL" (ByVal Dst As Any, ByVal Src As Any, ByVal Length As Long) As Integer
' declarations for MyStruct1
Declare Function CopyStruct1 Lib "DSTRCT32.DLL" Alias "CopyStruct" (ByVal Dst As Any, Src As MyStruct1, ByVal Length As Long) As Integer
Declare Function CopyStruct2 Lib "DSTRCT32.DLL" Alias "CopyStruct" (Dst As MyStruct1, ByVal Src As Any, ByVal Length As Long) As Integer
' declarations for MyStruct2
Declare Function CopyStruct3 Lib "DSTRCT32.DLL" Alias "CopyStruct" (ByVal Dst As Any, Src As MyStruct2, ByVal Length As Long) As Integer
Declare Function CopyStruct4 Lib "DSTRCT32.DLL" Alias "CopyStruct" (Dst As MyStruct2, ByVal Src As Any, ByVal Length As Long) As Integer
sub Convert ()
Dim Send1 As MyStruct1
Dim Recv1 As MyStruct1
Dim Send2 As MyStruct2
Dim Recv2 As MyStruct2
Dim Msg As String * 50
Dim ret, bytes As Integer
Send1.CustNum = 123456 ' to send the structure
Send1.CustName = "Nobody"
bytes = Len(Send1)
ret = CopyStruct1(Msg, Send1, bytes)
Socket.Send = Msg
Msg = Socket.Receive ' to receive the structure
bytes = Socket.Result
ret = CopyStruct2(Recv1, Msg, bytes)
Send2.Index = 10 ' convert MyStruct2
Send2.Value = 135
bytes = Len(Send2)
ret = CopyStruct3(Msg, Send2, bytes)
ret = CopyStruct4(Recv2, Msg, bytes)
End Sub
 <<   Table Of Contents   >> 

*Get Adobe Acrobat Reader if needed.



Browse FAQ

Related Products
Mail Objects

Recommended Add-On
Network Monitor,
Protocol Analyzer


Raves
"The night before I went on summer holiday we had to make some 'last minute' configuration changes to approx. 300 routers, a tedious job to do manually with telnet. We went along with MS Excel containing a list of IP-adresses to the routers, and the VIT telnet-component. One hour later the VBA-application (small is beautiful) was working, and after another hour all of our routers were updated with the new configuration. I just say a big "Thanks" to you all for a good sleep that night."
Eirik Brendholen, Ergo Integration AS

"We conducted a test session to compare the performance of similar products, and Distinct's product was better!" [more]
Dr. Shyam Sunder, Carnegie Mellon University

"Together with Distinct, we were able to offer our users an ideal soution to enabling them to connect to Yahoo! Pager, and to do so both quickly and reliably." [more]
Brian Park,
Producer of Yahoo! Pager, Yahoo! Inc.


  7/24/2008   Legal notices | PRIVACY Policy | Networking News |         Page Last Modified: 8/24/2001