Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. system object == true or false?????

system object == true or false?????

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++debugging
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Phil C
    wrote on last edited by
    #1

    Ok, here's what must be the stupidest question on the board, but I have to ask. I'm trying to migrate from C++ (VC6) to the new .NET style of managed C++. I'm trying to enumerate any/all NIC cards on the sytem and get a list of valid IP addresses using System:ManagementClass object At one point in my code I'm calling: ManagementObject * mo = new ManagementObject(); //do some stuff to enumerate through possible multiple objcts //then find out if this "object" has an IP address mo->get_Item("IPEnabled") Now the question This Get_Item() function returns a system object pointer. As I debug and step through my code, I can see this pointer does indeed point to an object which toggle between "true" and "false" What I'm trying to do is simple: if(mo->Equals(true)) { GO DO SOME STUFF } That if statement does not compile. calling Equals(false) compiles but always returns "true" (I guess because mo is not a NULL pointer) How do I test the value of a generic system object to see if it's "value" == true or false????? This seems like it should be so simple, yet is turning out to be so hard is embarrassing. Can anyone point me in the right direction?? Phrustrated Phil

    L 1 Reply Last reply
    0
    • P Phil C

      Ok, here's what must be the stupidest question on the board, but I have to ask. I'm trying to migrate from C++ (VC6) to the new .NET style of managed C++. I'm trying to enumerate any/all NIC cards on the sytem and get a list of valid IP addresses using System:ManagementClass object At one point in my code I'm calling: ManagementObject * mo = new ManagementObject(); //do some stuff to enumerate through possible multiple objcts //then find out if this "object" has an IP address mo->get_Item("IPEnabled") Now the question This Get_Item() function returns a system object pointer. As I debug and step through my code, I can see this pointer does indeed point to an object which toggle between "true" and "false" What I'm trying to do is simple: if(mo->Equals(true)) { GO DO SOME STUFF } That if statement does not compile. calling Equals(false) compiles but always returns "true" (I guess because mo is not a NULL pointer) How do I test the value of a generic system object to see if it's "value" == true or false????? This seems like it should be so simple, yet is turning out to be so hard is embarrassing. Can anyone point me in the right direction?? Phrustrated Phil

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Phil C wrote: What I'm trying to do is simple: if(mo->Equals(true)) { GO DO SOME STUFF } What you are doing there is totally absurd! A ManagementObject can NEVER EVER be a Boolean. Now if you are doing as you did originally, AFAIK you just need to unbox the return object pointer. EG

      if (__unbox(mo->get_Item("IPEnabled")))
      {
      //do the good stuff here
      }

      :) leppie::AllocCPArticle(Generic DFA State Machine for .NET);

      P 1 Reply Last reply
      0
      • L leppie

        Phil C wrote: What I'm trying to do is simple: if(mo->Equals(true)) { GO DO SOME STUFF } What you are doing there is totally absurd! A ManagementObject can NEVER EVER be a Boolean. Now if you are doing as you did originally, AFAIK you just need to unbox the return object pointer. EG

        if (__unbox(mo->get_Item("IPEnabled")))
        {
        //do the good stuff here
        }

        :) leppie::AllocCPArticle(Generic DFA State Machine for .NET);

        P Offline
        P Offline
        Phil C
        wrote on last edited by
        #3

        Oops, I wrote it wrong while trying to trim away all the fat and make it legible. What I'm trying should have read: Object *booltest = mo->get_Item("IPAddress"); if(booltest) { DO STUFF } //or if(booltest->Equals(true)) { DO STUFF } //and about fifteen other attempts all of which aren't quite right Basically the entire mo->GetItem("IPEnabled") was originally inside my if statement (like you wrote) and I was (trying to) break it down into pieces to determine where I was going wrong. Thank you for telling me I'm totally absurd. I was really hoping someone like you would tell me how stupid I am even though I admitted right up front that this is a pretty embarrassing question. I think you did point me to the key statement though. I haven't figured out the whole box/unbox theory yet. For that I do thank you sincerely. Less Phrustrated Phil

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups