Solved

How to convert Object^ returned from RegistryKey.OpenSubKey

Posted on 2009-04-08
4
708 Views
Last Modified: 2013-12-14
Hello,
I am writing a function to decode Microsoft's digital product id from the registry using .NET's RegistryKey class.  The function call works properly and returns an Object^.  When I examine this object in the debugger, it shows it as a System::Array with 164 elements, which is perfect.  My problem is how to convert the Object into some kind of BYTE array so I can continue decoding the digital id.  I have tried everything that I can think of ... boxing.. unboxing... casting... tostring()...  iteration... Nothing works!  I've scoured the Internet and find tons of references if I was using VB or C#, but nothing about C++.  I hope that someone can help!  It is making me CrAzY!!!

Thank you,

Mike
Object ^o = lm->OpenSubKey("ABOHHIVE\\Microsoft\\Windows NT\\CurrentVersion")->GetValue("DigitalProductId")
 
How can I convert it to an array of BYTES?

Open in new window

0
Comment
Question by:mjgardne
  • 2
4 Comments
 
LVL 6

Expert Comment

by:HarryNS
ID: 24094944
RegistryKey ^ rk = Registry::CurrentUser->CreateSubKey( L"RegistryOpenSubKeyExample" );
0
 

Author Comment

by:mjgardne
ID: 24101241
Thanks for the response Harry, but, unfortunately, your advice doesn't resolve my issue...   CreateSubKeyfunction description from msdn: "Creates a new subkey or opens an existing subkey for write access.".   I can read the data, but I cannot figure out how to convert it from Object^ to an array of BYTES.  When I examine the returned value in the debugger, I see all the correct data and that it is a System::Array with 164 elements...  All of that is perfect, but I need an array to process...  How do I get it?

Thanks for the suggestion...  :)
Mike
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 24112456
What value does GetType() http://msdn.microsoft.com/en-us/library/system.object.gettype.aspx return when you call it for o?
0
 

Accepted Solution

by:
mjgardne earned 0 total points
ID: 24112527
I've resolved this issue myself...  Here is the solution:

Object ^o = lm->OpenSubKey("ABOHHIVE\\Microsoft\\Windows NT\\CurrentVersion")->GetValue("DigitalProductId");

array<BYTE> ^buf = safe_cast<array<BYTE>^>(o);
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question