?
Solved

C# foreach statment to managed C++

Posted on 2005-05-06
1
Medium Priority
?
814 Views
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")
  lstHost.Items.Add(dPC.Name);
     
}
}

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();
while(enDom->MoveNext())
{
while(enPC->MoveNext())
{
if(dPC->SchemaClassName == "Computer")
                                                 usersLstbx->Items->Add(dPC->Name);
}//end for
}//end for

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

0
Comment
Question by:fsharer
1 Comment
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 900 total points
ID: 13947759
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")
                    usersLstbx->Items->Add(dPC->Name);
       }
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

840 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