Re: Re: Reading UDTs out of a byte array (CopyMemory vs Get on a disk file)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Beowulf (beowulf_is_not_here_at_hotmail.com)
Date: 06/18/04


Date: Fri, 18 Jun 2004 15:00:41 -0400

On Fri, 18 Jun 2004 19:48:46 +0100, Gale Green
<gale@databeat.fsnet.co.uk> ejaculated:

>On Fri, 18 Jun 2004 14:26:17 -0400, Beowulf
><beowulf_is_not_here@hotmail.com> wrote:
>
>> Ok, I've been banging my head against the wall on this one for the
>> better part of a day, now and am hoping someone can point me in the
>> right direction.
>
>That's a lot of code to plough through. <g>

Sorry. :( I'll appreciate any comments

>I don't think you show what values are in the record size constants
>(e.g., VAX_DBSV_REC_SIZE), but do remember that VB strings are Unicode
>so, "String * 6" means 12 bytes.

VAX_TSTAMP_REC_SIZE = 64
VAX_DBSV_REC_SIZE = 128

>If a UDT contains just two String * 6 members then you have to
>CopyMemory 24 bytes from your file buffer.

That thought had occurred to me, but when I altered the values of
these constants to account for Unicode, then I could not read the
header record correctly and reading the "variable records" was even
more messed up than it is now. If I read VAX_DBSV_REC_SIZE bytes out
of my byte array with CopyMemory, the first several fields are all
correct, including fields that come after dbsv_seg_var_name. The
misalignment occurs within the UDT. However, the next UDT gets read
out of the byte array starting at the right spot. It's because of
this that I suspect the issue has to do with how VB aligns or pads
data within UDTs.

Also, I forgot to include the declaration for data_base_seg_vars in my
original message. So, some more code is included below. Thanks.

Public Type data_base_seg_vars
    dbsv_left_ptr_offset As Long ' Offset value for next
left pointer
    dbsv_right_ptr_offset As Long ' Offset value for the
next right pointer
    dbsv_balancing_byte As Byte ' Binary tree routine
balancing byte
    dbsv_unique_variable As String * 1 ' "U" = unique def. of
var, "M" = appears on other segs
    dbsv_seg_var_name As String * 16 ' Segment.variable name
without the "."
    dbsv_offset_value As Integer ' Equal to
occurence_number
    dbsv_var_attribute As Byte ' "C" = char, "N" =
numeric, "D" = date, "P" = phone
    dbsv_var_status As Byte ' "A" = active, "D" =
deleted
    dbsv_format_offset_h As Long ' Offset value for
pointer into hard format table
    ' crap as integer - offset 34
    dbsv_format_offset_s As Long ' Offset value for
pointer into soft format table
    dbsv_segment_offset As Long ' Offset value for
pointer into segment table
    dbsv_var_offset As Integer ' Offset value for
pointer into variable addr in segment
    dbsv_lo_bound As Integer ' Low bound dimension of
array
    ' crap as integer - offset 46
    dbsv_hi_bound As Integer ' High bound dimension
of array
    dbsv_var_length As Integer ' Length of variable as
defined in data dictionary
    dbsv_var_new_length As Integer ' Corrected length to
replace current length after DD is reorged
    ' crap as byte - offset 54
    dbsv_redefine_begin As Integer ' For overlay vars only,
dbsv_offset_value of 1st redefined var
    dbsv_default_missing_values As String * 4 ' Missing value offset
size
    dbsv_order_number As Integer ' Allows listing vars in
an order different from occnum or alpha
    ' crap as integer - offset 64
    dbsv_var_label As String * 40 ' Variable label
    dbsv_digits_only As Byte ' "D" = digits only for
a char var, " " = otherwise
    dbsv_response_require As Byte ' "R" = response
required for char var instead of formats, " " = otherwise
    dbsv_question_number As String * 5 ' Questionnaire number
for this variable
    dbsv_available_byte As Byte ' Unused
    dbsv_order_number_ptr As Long ' Ptr to order number
node (ord_num_node)
    dbsv_new_format_offset_h As Long ' If length changes,
this points to future hard format
    dbsv_new_format_offset_s As Long ' If length changes,
this points to future soft format
    dbsv_delivery_flag As Byte ' " " = var will be
delivered, "N" = NOT delivered
    dbsv_redefine_end As Integer ' For overlay vars only,
dbsv_offset_value of last redefined var
    dbsv_next_var_num As Integer ' Position of next var
(for traversing seg by order num)
    dbsv_filler_1 As Byte
End Type

--
What do you get when you multiply 6 by 9?


Relevant Pages

  • Re: using "!!" in "c"
    ... that Keith was". ... Here's what the standard says about the "%p" format for the *printf ... The argument shall be a pointer to void. ... converting an integer to a pointer-to-function might ...
    (comp.lang.c)
  • Re: offsetof() macro
    ... > To my untrained eye that would basically result in a null pointer. ... The offsetofmacro is "special", as are many other things in the ... the structure definition, they know the offset of the first member, ... And the compiler ...
    (comp.lang.c)
  • Re: vscanf and vprintf
    ... They take a pointer to a list of arguments rather than the arguments ... How can I write a function that takes a format string and a variable ... number of arguments, like printf, and passes them to printf to do most ... variable-length argument list, they accept a single va_list pointer. ...
    (comp.lang.c)
  • Re: Silly new instructions
    ... what you have is a pointer or integer. ... - Pointers are always intervals of memory addresses, ... The tag bit in the second word ... interval plus offset. ...
    (comp.arch)
  • Re: struct named 0
    ... >> expression yields undefined behavior. ... null pointer constants. ... > derived by adding an offset to the null pointer is cast to an integer. ...
    (comp.lang.c)