venta: (Default)
venta ([personal profile] venta) wrote2008-04-03 04:45 pm
Entry tags:

Help needed :(

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 ?

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

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

[identity profile] erming.livejournal.com 2008-04-03 04:26 pm (UTC)(link)
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...

[identity profile] venta.livejournal.com 2008-04-03 04:31 pm (UTC)(link)
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 2008-04-03 16:41 (UTC)

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

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

[personal profile] pm215 2008-04-03 04:21 pm (UTC)(link)
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?

[identity profile] venta.livejournal.com 2008-04-03 04:24 pm (UTC)(link)
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.

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

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

Thanks a lot.