msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Looking for a better way to do this

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions
Author Message
Robert Morley



Joined: 22 Dec 2007
Posts: 176

PostPosted: Thu Feb 28, 2008 12:04 am    Post subject: Looking for a better way to do this Reply with quote

Okay, I'm trying to manually process a field full of binary data, and I'm
trying to figure out if there's a better way than the fairly obvious "hard way".

Field data is stored in a Variant Array of Bytes as follows:

JunkData(0 to 17)
LengthOfEntry1(18 to 21) 'Little-Endian Long Value
Entry1(22 to whatever)
LengthOfEntry2(x to x + 3) 'Little-Endian Long Value
Entry2(x + 4 to whatever)

(If anybody's curious, this is the PR_REPORT_TAG field a message is tagged
with by Exchange Server when read receipts are requested. There seem to
only ever be two entries, and they SHOULD always be 46 and 16 bytes
respectively in a pure Exchange Server environment, as far as I can tell,
but since specs just don't seem to be out there, I'd like to actually read
in the length values and parse them properly.)

What I need out of this is each Entry field returned as a continuous string
of characters. So if LengthOfEntry1 = 3 and Entry1 was (AB CD EF), then I
would get "ABCDEF" as my first entry string.

I can easily write the code to slog through this "the hard way" and do
LengthOfEntry = b1 + b2 * 256 + ..., Loop over LengthOfEntry bytes
converting each to Hex and appending it to a string. I'm just wondering if
there's a better way to do this that's straight-forward. I'd prefer to
avoid RtlMoveMemory and similar API calls, but it's not entirely out of the
question, as I can certainly see the how it would make things easier.


Rob

Archived from group: microsoft>public>vb>general>discussion
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Wed Feb 27, 2008 9:23 pm    Post subject: Re: Looking for a better way to do this Reply with quote

Robert Morley wrote:
> Okay, I'm trying to manually process a field full of binary data, and I'm
> trying to figure out if there's a better way than the fairly obvious "hard way".
>
> Field data is stored in a Variant Array of Bytes as follows:
>
> JunkData(0 to 17)
> LengthOfEntry1(18 to 21) 'Little-Endian Long Value
> Entry1(22 to whatever)
> LengthOfEntry2(x to x + 3) 'Little-Endian Long Value
> Entry2(x + 4 to whatever)

That "Variant Array of Bytes" has me confused. This is a Byte array stored within a
Variant? Is that necessary? I mean, instead of just using a standard Byte array?
--
..NET: It's About Trust!
http://vfred.mvps.org
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Wed Feb 27, 2008 9:32 pm    Post subject: Re: Looking for a better way to do this Reply with quote

Karl E. Peterson wrote:
> Robert Morley wrote:
>> Okay, I'm trying to manually process a field full of binary data, and I'm
>> trying to figure out if there's a better way than the fairly obvious "hard way".
>>
>> Field data is stored in a Variant Array of Bytes as follows:
>>
>> JunkData(0 to 17)
>> LengthOfEntry1(18 to 21) 'Little-Endian Long Value
>> Entry1(22 to whatever)
>> LengthOfEntry2(x to x + 3) 'Little-Endian Long Value
>> Entry2(x + 4 to whatever)
>
> That "Variant Array of Bytes" has me confused. This is a Byte array stored within
> a Variant? Is that necessary? I mean, instead of just using a standard Byte
> array?

The reason I ask is because de-referencing the array within the Variant is gonna get
really nasty really fast. You'd want to have a really good reason to do so.
Wikipedia actually gives the basics:

http://en.wikipedia.org/wiki/Variant_type

Then, as Jonathan points out here:

http://forums.devx.com/archive/index.php/t-37031.html

In the case of an array, the Variant "data" is actually a pointer to a SAFEARRAY.
Been lots of threads here about picking those apart. Will get tiresome unless you
have a non-trivial need.
--
..NET: It's About Trust!
http://vfred.mvps.org

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group