venta: (Default)
[personal profile] venta
Does anyone know anything about .NET ?

I'm writing a .NET app (Managed C++) which manipulates registry keys. Which is fine.

You call GetValue on the subkey, passing in the name of the value you want to retrieve. The returned object is of type Sytem::Object, but you can cast it to an int or a string (depending on type) and all is well.

Except... what if your registry value is binary ? Then you can't cast it to an integer (it throws an exception, not unreasonably, presumably as it can't guarantee value is small enough to fit into an int). You are, in fact, left with a System::Object which is round, and smooth, and shiny and has absolutely no means of accessing the value contained therein.

At least, no means that I can determine. Just how do I persuade the binary value out of it ?

Date: 2008-04-03 04:10 pm (UTC)
From: [identity profile] erming.livejournal.com
I'm guessing you call the object's to string method then do stuff based on how you think it is encoded.

Date: 2008-04-03 04:21 pm (UTC)
From: [identity profile] smorgasbord.livejournal.com
RegistryKey.GetValueKind()

Date: 2008-04-03 04:21 pm (UTC)
pm215: (Default)
From: [personal profile] pm215
Er, doesn't the C++ example in http://msdn2.microsoft.com/en-us/library/fdf576x1(VS.85).aspx tell you what you have to do?

Date: 2008-04-03 04:23 pm (UTC)
From: [identity profile] venta.livejournal.com
ToString() returns "SytemByte*" where * is an unprintable character. I don't have much clue how I think it's encoded :(

Date: 2008-04-03 04:23 pm (UTC)
From: [identity profile] venta.livejournal.com
Er, won't that just tell me that the registry value is binary ? Which I already know.

Date: 2008-04-03 04:24 pm (UTC)
From: [identity profile] venta.livejournal.com
Not that I've noticed... could you be a bit more specific ? Me and MSDN don't get on well, and I have immense difficulty extracting any information from it at all.

Date: 2008-04-03 04:25 pm (UTC)
From: [identity profile] venta.livejournal.com
Ah. Got it. I think.

Date: 2008-04-03 04:26 pm (UTC)
From: [identity profile] erming.livejournal.com
No but you could do

Image mypic = (Image)getValue().ToString() or something similar, where the binary is represented as an image.

but at the end of the day you need to know what the binary is meant to represent...

Date: 2008-04-03 04:28 pm (UTC)
From: [identity profile] venta.livejournal.com
Yes, it does. Can't believe I missed it.

Thanks a lot.

Date: 2008-04-03 04:31 pm (UTC)
From: [identity profile] venta.livejournal.com
It seems (see below) that the correct answer is to cast it to array<Byte>^ - something I'd tried to do already, but obviously got the syntax wrong (but wrong in such a way that it still compiled). Me and the hats don't get on so well yet :(
Edited Date: 2008-04-03 04:41 pm (UTC)

Profile

venta: (Default)
venta

December 2025

S M T W T F S
 123456
78910111213
14151617181920
212223 24252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 27th, 2025 12:30 pm
Powered by Dreamwidth Studios