Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 752
  • Last Modified:

How to convert Object^ returned from RegistryKey.OpenSubKey

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
mjgardne
Asked:
mjgardne
  • 2
1 Solution
 
HarryNSCommented:
RegistryKey ^ rk = Registry::CurrentUser->CreateSubKey( L"RegistryOpenSubKeyExample" );
0
 
mjgardneAuthor Commented:
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
 
LordOfPortsCommented:
What value does GetType() http://msdn.microsoft.com/en-us/library/system.object.gettype.aspx return when you call it for o?
0
 
mjgardneAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now