-
February 26th, 2010, 09:45 AM
#1
Binary data to a user defined type
Hello,
I have a problem with converting binary data to a user defined type in vb6.0
I have tried to use the RtlMoveMemory function:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
this way:
CopyMemory ByVal VarPtr(TransTabType), ByVal VarPtr(rs.Fields("NET_MSG")), Len(rs.Fields("NET_MSG")
where TransTabType is a user-defined type:
Private Type TransTab
in_out As Integer
node_id As Integer
group_id As Integer
vogn_id As Integer
koding As Integer
retry As Integer
seq_no(0 To 9) As Byte
trans_type As Integer
error_no As Integer
status_ok As Integer
count_send_no As Integer
channel_no As Integer
base_id As Integer
lengtext As Integer
last_send_time As Long
info_text() As Byte
End Type
And rs.Fields("NET_MSG") is binary data recived from a database.
When I try to run this, the user defined type just got rubbish data.
If the data was in a binary file I could hav used GET function, but in my case
I receive it from a sql database.
Anyone have any ideès, so please help me..?
Best Regards
Paal Fredrik
-
February 26th, 2010, 09:53 AM
#2
Re: Binary data to a user defined type
What data type is the field "NET_MSG" exactly?
The only problem I'd see is the info_Text() as Byte which is a dynamic type. I'm not sure if that's good in a UDT
-
March 2nd, 2010, 05:11 PM
#3
Re: Binary data to a user defined type
Unless the source data has exactly the same structure as the destination data structure, you cannot just use Copymemory. You must assign that data part individually like assigning a particular variable to a UDT element.
And just like what WoF have observed, this "info_Text() as Byte" which part of your UDT, will prevent you from moving data "by blocks" because being a dynamic array, they dont always have the same sizes.
It may be permissible to use dynamic array inside a UDT but it will always be at the cost of assigning values individually. And besides -- by the way -- it will work only when manipulating in memory -- not from a file source.
Marketing our skills - please participate in the survey and share your insights
-
-
March 3rd, 2010, 08:54 AM
#4
Re: Binary data to a user defined type
Yes. The dynamic array would be only a pointer within the structure, counting 4 bytes while the actual array data is elsewhere in memory and does not count to the length of the structure.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|