Click here to Skip to main content
11,496,146 members (605 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: C# VB.NET
I have this bit of code from WMP11 SDK that returns an incorrect value.

Case CreateEditor.WMT_ATTR_DATATYPE.WMT_TYPE_GUID
tagValue = "{" & BitConverter.ToString(attribValue) & "}"

' tagValue = BitConverter.ToString(attribValue, 0, attribValue.Length)
' tagValue = Convert.ToBase64String(attribValue)
' tagValue = System.Text.UnicodeEncoding.ASCII(attribValue)
' tagValue = Encoding.ASCII.GetString(attribValue)
' tagValue = Encoding.Unicode.GetString(attribValue)
' tagValue = Encoding.UTF8.GetString(attribValue)

I have commented out other things I have tried. Most of them return gibberish.
attribValue.tostring returns {System.Byte[]}.

The above code (bitconverter.tostring) returns {BC-7D-60-D1-23-E3-E2-4B-86-A1-48-A4-2A-28-44-1E-00}.

I have another app that uses AxInterop.WMPLib and it returns {D1607DBC-E323-4BE2-86A1-48A42A28441E} as it should.

Any suggestions on what I might try?
Is there a way to determine what encoder was used?

Thank you
Posted 30-Apr-12 6:43am
rctaubert2.5K
Comments
SAKryukov at 30-Apr-12 11:54am
   
Reason for my vote of 1
The question is totally incorrect. The answer depends on the content of the array of character, on what was serialized and, in case of text, in what encoding. I can see failure to understand it and pointless trial-and-error approach, a very dangerous trend in learning programming.
--SA
rctaubert at 30-Apr-12 12:21pm
   
"depends on the content of the array of character" I gave you that. {BC-7D-60-D1-23-E3-E2-4B-86-A1-48-A4-2A-28-44-1E-00} or if you prefer {188-125-96-209-35-227-226-75-134-161-72-164-42-40-68-30.0}

"on what was serialized" WMT_TYPE_GUID as evidenced by the return from WMPLib {D1607DBC-E323-4BE2-86A1-48A42A28441E}

"in what encoding" I would imagine that if I knew that I wouldn't be posting this question.

"pointless trial-and-error approach" I tried Goodling the problem and all of my 'trial-and-error' were recommendations to similar questions. At least I was trying to find an answer.

But I do want to thank you for taking time out of your busy schedule to leave your comment. It's just too bad you couldn't find something positive to offer.
rctaubert at 30-Apr-12 13:11pm
   
Again, thank you for replying.

From your statement "This is pointless, because no one except you knows what was actually encoded (serialized) as an array of byte." I believe it is you that doesn't understand

I didn't write this code. As I pointed out it comes from Microsoft's SDK for Windows Media Player 11. It is used to provide metadata from .wma files (songs). I DID NOT write the code and I DID NOT supply the data.

It works except for this one piece of code. I didn't realize it was returning an incorrect value until I saw what WMPLib returned. Some research lead me to conclude that WMPLib was correct.

Thank you for your suggestions concerning system.guid. However, none of them will take an argument of type system.byte[].
SAKryukov at 30-Apr-12 14:28pm
   
Sorry, I've written it in a wrong way. Please see the updated answer. It could be GUID byte-by-byte or per member. Please understand that I only trying to decipher the rebus -- I probably should not have done it. Still, a pointless question. You did not even published the byte values.
--SA
rctaubert at 30-Apr-12 14:46pm
   
You stated "You did not even published the byte values." Look back at my first replly to you.

"depends on the content of the array of character" I gave you that. {BC-7D-60-D1-23-E3-E2-4B-86-A1-48-A4-2A-28-44-1E-00} or if you prefer {188-125-96-209-35-227-226-75-134-161-72-164-42-40-68-30.0}

As to your reference to system.bitconverter if you will look at my original post, that is what MSs code uses and it doesn't return a correct value.

But thank you anyway.
SAKryukov at 30-Apr-12 18:59pm
   
You say that this is what bitConverter returns, not as this is on input, which is less obvious. So, 17 bytes in this order (BC comes at the index[0]). Well, this is 136 bits, but GUID is 128 bits.

OK, and why do you think that {D1607DBC-E323-4BE2-86A1-48A42A28441E} (GUID) is correct. Your bytes present who-knows-which three bytes BC-7D-60 and the GUID {D1607DBC-E323-4BE2-86A1-48A42A28441E}. To get this GUID, you need the bytes in reverse order, rightmost 00 being the least significant byte...

Look, I think this is the pointless game of bytes. Without something documented thing it looks just a waste of time. I don't have even the idea why deserializing this at all...
--SA
rctaubert at 3-May-12 11:39am
   
Let me recap. The app produces a byte array named attribValue which contain 17 bytes with the values {188,125,96,209,35,227,226,75,134,161,72,164,42,40,68,30,00} for the song I have been using in my tests.

The expected result with this particular set of values is {D1607DBC-E323-4BE2-86A1-48A42A28441E}. I know this through some research into Microsofts metadata for songs.

Dim myGuid As New Guid(byte()) will produce a GUID BUT it requires only 16 bytes.

The problem now is that attribValue is 17 bytes long. Is there a way I can delete the last byte or copy all but the last byte to a new variable.

The following code will manually produce the correct result:
Dim aValue() As Byte = {188, 125, 96, 209, 35, 227, 226, 75, 134, 161, 72, 164, 42, 40, 68, 30} (NOTE missing last byte)
Dim myGuid As New Guid(aValue)
tagValue = myGuid.ToString
rctaubert at 3-May-12 16:14pm
   
I have finally come up with code that works, though hardly elegant. The code is as follows:

Dim i As Integer = 0
Dim byteList As List(Of Byte) = New List(Of Byte)
For Each b As Byte In attribValue
byteList.Add(b)
i += 1
If i = 16 Then Exit For
Next
Dim aValue As Byte() = byteList.ToArray
Dim myGuid As New Guid(aValue)
tagValue = myGuid.ToString

Can you think of a better way of doing this?
SAKryukov at 8-May-12 13:15pm
   
Now, that finally makes it clear. Just simplify it: use a regular "for" loop 0..15.
--SA

1 solution

Do or Do not. There is no try.
Please see: http://www.youtube.com/watch?v=q3hn6fFTxeo[^].

Please see my comment to the question. This is pointless, because no one except you knows what was actually encoded (serialized) as an array of byte. This is not a programming question, as it should be pose in this forum, but a pure rebus. Smile | :)

However, as you provided some indirect information and the expected result, let's try to guess what it could be. The encoded value was probably not a string. It could be GUID, but not in the string form. By the way, you should generally get a habit to work with data, not its string representation. So, assuming this is GUID, you could try to deserialize you array of chars as GUID, per component using BitConverter using the methods System.Guid.Parse, System.Guid.TryParse, System.Guid.ParseExact or System.Guid.TryParseExact, please see:
http://msdn.microsoft.com/en-us/library/system.guid.aspx[^],
http://msdn.microsoft.com/en-us/library/system.bitconverter.aspx[^].

If this works, you should just work with this GUID value. You only need string to present it in a text file, show on screen, etc. As with any other data, you would need one of ToString methods.

—SA
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 RyanDev 230
1 Sergey Alexandrovich Kryukov 114
2 Richard Deeming 100
3 OriginalGriff 89
4 Mostafa Asaduzzaman 59
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 30 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100