Managed C++ - Question

  • Thread starter Thread starter Rainer Sinsch
  • Start date Start date
R

Rainer Sinsch

Hi everyone,

I'm relatively new to managed c++ (though experienced in unmanaged c++), but
I just can't figure out how to do the following c-sharp lines in managed c++
(studio 2003). Can anyone enlighten me, please?

Following is a simple C-Sharp-Source for reading out wireless lan
signal-strength:

using System;
using System.Management;
class App
{
public static void Main()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
@"root\WMI",
"select Ndis80211ReceivedSignalStrength from
MSNdis_80211_ReceivedSignalStrength where active=true");
foreach (ManagementObject mo in searcher.Get())
{
Console.WriteLine("{0}",mo["Ndis80211ReceivedSignalStrength"]);
}
}
}

Thanks in advance
Rainer Sinsch
 
You can't mix C# in managed C++. You can either recode it as managed C++ (no
foreach), or create a new C# project and then the code will compile. You will
be able to call the C# code from managed C++, if needed.
 
Rainer Sinsch said:
Hi everyone,

I'm relatively new to managed c++ (though experienced in unmanaged c++), but
I just can't figure out how to do the following c-sharp lines in managed c++
(studio 2003). Can anyone enlighten me, please?

Following is a simple C-Sharp-Source for reading out wireless lan
signal-strength:

using System;
using System.Management;
class App
{
public static void Main()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
@"root\WMI",
"select Ndis80211ReceivedSignalStrength from
MSNdis_80211_ReceivedSignalStrength where active=true");
foreach (ManagementObject mo in searcher.Get())
{
Console.WriteLine("{0}",mo["Ndis80211ReceivedSignalStrength"]);
}
}
}

ManagementObjectSearcher.Get returns ManagementObjectCollection.
ManagementObjectCollection.GetEnumerator returns ManagementObjectEnumerator.
and then while(ManagementObjectEnumerator.MoveNext())
ManagementObjectEnumerator.Current returns ManagementBaseObject, of which
ManagementObject is derived.
 
Thanks Michiel - it worked just fine.

Just in case anyone else wants to know, here's the source for reading out
the current signal strength on the last wireless lan adapter installed (in
case you have more than 1). Anyway, the source can be easily changed.

int GetSignalStrength()
{
ManagementObjectSearcher *searcher = new ManagementObjectSearcher(
"root\\WMI",
"select Ndis80211ReceivedSignalStrength from
MSNdis_80211_ReceivedSignalStrength where active=true");

ManagementObjectCollection *queryCollection = searcher->Get();

ManagementObjectCollection::ManagementObjectEnumerator* queryEnum =
queryCollection->GetEnumerator();
while (queryEnum->MoveNext());

ManagementBaseObject* object = queryEnum->get_Current();
Object* signalStrength =
object->GetPropertyValue(L"Ndis80211ReceivedSignalStrength");
return (Convert::ToInt32(signalStrength->ToString()));
}

Best regards
rainer

Michiel said:
Rainer Sinsch said:
Hi everyone,

I'm relatively new to managed c++ (though experienced in unmanaged c++), but
I just can't figure out how to do the following c-sharp lines in managed c++
(studio 2003). Can anyone enlighten me, please?

Following is a simple C-Sharp-Source for reading out wireless lan
signal-strength:

using System;
using System.Management;
class App
{
public static void Main()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
@"root\WMI",
"select Ndis80211ReceivedSignalStrength from
MSNdis_80211_ReceivedSignalStrength where active=true");
foreach (ManagementObject mo in searcher.Get())
{
Console.WriteLine("{0}",mo["Ndis80211ReceivedSignalStrength"]);
}
}
}

ManagementObjectSearcher.Get returns ManagementObjectCollection.
ManagementObjectCollection.GetEnumerator returns ManagementObjectEnumerator.
and then while(ManagementObjectEnumerator.MoveNext())
ManagementObjectEnumerator.Current returns ManagementBaseObject, of which
ManagementObject is derived.
 
Back
Top