C# foreach statment to managed C++

Posted on 2005-05-06
Last Modified: 2013-12-03
How would I convert this to managed C++

DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach(System.DirectoryServices.DirectoryEntry dDom in root.Children)
foreach(System.DirectoryServices.DirectoryEntry dPC in dDom.Children)
   if (dPC.SchemaClassName == "Computer")

This is what I had and compiles but gives me an unhandled exception error
DirectoryEntry *root = new DirectoryEntry("WinNT");
System::DirectoryServices::DirectoryEntry *dDom;
System::DirectoryServices::DirectoryEntry *dPC;
IEnumerator *enDom = dDom->Children->GetEnumerator();
IEnumerator *enPC = dPC->Children->GetEnumerator();
if(dPC->SchemaClassName == "Computer")
}//end for
}//end for

I am trying to fill a listbox with users on our domain, using Visual Studio Any help is greatly appreciated

Question by:fsharer
    1 Comment
    LVL 55

    Accepted Solution

    I think it must be something like:

    System::DirectoryServices::DirectoryEntry *root = new DirectoryEntry("WinNT:");

    System::Collections::IEnumerator* enDom = root ->Children->GetEnumerator();
    while (enDom ->MoveNext())
          DirectoryEntry* dDom= __try_cast<DirectoryEntry*>(enDom ->Current);
          System::Collections::IEnumerator* enPC = dDom ->Children->GetEnumerator();
          while (enPC ->MoveNext())
                  DirectoryEntry* dPC = __try_cast<DirectoryEntry*>(enPC ->Current);
                  if(dPC->SchemaClassName == "Computer")

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Title # Comments Views Activity
    Client socket stops responding on client 9 39
    Formula for Barcode Scanning within Excel 2010 3 60
    Parsing HTML in C# 10 102
    Identify font 3 48
    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now