Solved

How to convert Object^ returned from RegistryKey.OpenSubKey

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

746 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

8 Experts available now in Live!

Get 1:1 Help Now