Solved

How to convert Object^ returned from RegistryKey.OpenSubKey

Posted on 2009-04-08
4
722 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

820 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