Solved

How to convert Object^ returned from RegistryKey.OpenSubKey

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now