Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:24:30+00:00 2026-05-22T02:24:30+00:00

I have done pretty much all my programming using C# and very much a

  • 0

I have done pretty much all my programming using C# and very much a newbie to C++. However now I have to convert to C++ and is finding it a bit difficult. For example, I wrote a pretty simple program using C# to acquire a RegistryKey, then using a recursive function I iterate through my registry key to find a specific key and then get the values I want. No problem, I can write that program in 10 minutes using C#. Here is the code.

My primary function. It gets Bluetooth Registry Key and then call the recursive function.

private static void CheckOpenComPorts()
{
            RegistryKey blueToothPorts = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\Bluetooth");

            List<string> foundPorts = new List<string>();
            AddFoundPortsToList(blueToothPorts, ref foundPorts);

            //Rest of the program; not relevant here.            
}

Recursive Function. Iterates the passed Key to find out necessary values.

private static void AddFoundPortsToList(RegistryKey regKey, ref List<string> ports)
        {
            try
            {
                string[] subKeys = regKey.GetSubKeyNames();

                if (subKeys != null)
                {
                    foreach (string subKey in subKeys)
                    {
                        AddFoundPortsToList(regKey.OpenSubKey(subKey), ref ports);
                    }
                }

                if (regKey.Name.EndsWith("Device Parameters"))
                {
                    string str = System.Convert.ToString(regKey.GetValue("PortName"));
                    if (String.IsNullOrEmpty(str) == false)
                    {
                        ports.Add(str);
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                ;
            }
        }

The above code works fine, but when I tried to convert it to C++, I’m pretty lost.
Note : I’m using a Win32 Console C++ Program.

I figured out that I can do something like the following to get the Bluetooth Registry Key.

RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Enum\\Bluetooth", 0, KEY_READ, &hKey)

But after that, I’m pretty lost about the recursive function. Specially, how do I get the available subkeys of the passed registry key when I do NOT know the subkey names?. Or in short, what is the equivalent behavior of RegistryKey.GetSubKeyNames() in C++?

As I am only beginning this thing a code sample with some explanations would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:24:31+00:00Added an answer on May 22, 2026 at 2:24 am

    I’m assuming you want to transition from .NET to native C++ programming. (i.e. no CLI and no .NET framework, which you could still use if you enabled managed C++ compilation).

    If you spent a ton of time in C# land, you are probably very used to a ton of very convenient classes for just about everything imaginable and all you have to do is hit “.” and let the Intellisense list the methods. Well…. you can forget all those conveniences 🙂

    There is no such (at least not complete) framework in C++ so often you have to turn to Win32 API. MSDN Library is YOUR FRIEND. If you want to get good at C++, learn how to read it and learn how to look things up (not just by name, but learn where different categories are). In this case, if you search for the function you found, you will find a whole set of functions that work on registry. So now, looking at other methods in the same category in MSDN library, you can find RegEnumKeyEx. (hint: make sure to switch MSDN library UI to classical view, that makes it much easier to navigate between topics. I don’t know what MS was thinking with their “new” look and feel)

    As you start using Win32 API you will realize what a pain it is, especially coming from C#. But you don’t have to use it directly (or at least not every time). You can use other libraries, for example ATL provides you with CRegKey class which makes working with registry much simpler. If you can’t find the class, do what C++ does best, write your own class. Constantly working directly with windows functions will make your code very, very long and a pain to read.

    Another 2 libraries worth knowing as you get into C++ are STL (a must) and Boost (strong should). Boost especially has a lot of OS abstraction so you don’t have to go directly to windows DLLs every time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have not done much database programming at all. I am working from some
I have built a PHP calendar system and have pretty much everything done but
I have a set of operations that are very expensive but are all pretty
The title pretty much says it all. A cookie seems to have a few
I have done Java and JSP programming in the past, but I am new
I have done a bit of testing on this myself (During the server side
I have done a bit of research into this and it seems that the
I have done a little Django development, but it has all been in a
Title says it pretty much all : is there a way to get the
I'm using Django 1.1, and I have this template, a base template, that all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.