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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. CLI/BOOL to bool conversion.

CLI/BOOL to bool conversion.

Scheduled Pinned Locked Moved Managed C++/CLI
csharpquestionc++help
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.
  • M Offline
    M Offline
    Mike Doner
    wrote on last edited by
    #1

    I've got a C++ app that makes calls into a C# library. One of the calls in the C# lib is: void myFunc ( bool Flag ) I've done some marshalling for strings in other functions, but the bool has me scratching my head. How do I convert my C++ BOOL to a .NET bool for my C# call? What am I overlooking? Any help you could send would be appreciated. Cheers. Mike.

    N 1 Reply Last reply
    0
    • M Mike Doner

      I've got a C++ app that makes calls into a C# library. One of the calls in the C# lib is: void myFunc ( bool Flag ) I've done some marshalling for strings in other functions, but the bool has me scratching my head. How do I convert my C++ BOOL to a .NET bool for my C# call? What am I overlooking? Any help you could send would be appreciated. Cheers. Mike.

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      Mike Doner wrote:

      How do I convert my C++ BOOL to a .NET bool for my C# call?

      The C++ BOOL translates to the C# int. In C++, a BOOL evaluates to FALSE if it's 0,and to TRUE if it's non-zero (though typically TRUE evaluates to 1). To convert a BOOL value to the C# bool, compare with 0. Example:

      BOOL cpp = TRUE;

      bool cs = (bool)(cpp != 0); // the cast may or may not be needed, you can check that out.

      C++/CLI correctly treats bool as the .NET bool type. [Edit]when I said evaluate above, it practically means a #define since there is no actual evaluation there[/Edit]

      Regards, Nish


      My technology blog: voidnish.wordpress.com Code Project Forums : New Posts Monitor This application monitors for new posts in the Code Project forums.

      modified on Tuesday, September 28, 2010 1:02 PM

      M 1 Reply Last reply
      0
      • N Nish Nishant

        Mike Doner wrote:

        How do I convert my C++ BOOL to a .NET bool for my C# call?

        The C++ BOOL translates to the C# int. In C++, a BOOL evaluates to FALSE if it's 0,and to TRUE if it's non-zero (though typically TRUE evaluates to 1). To convert a BOOL value to the C# bool, compare with 0. Example:

        BOOL cpp = TRUE;

        bool cs = (bool)(cpp != 0); // the cast may or may not be needed, you can check that out.

        C++/CLI correctly treats bool as the .NET bool type. [Edit]when I said evaluate above, it practically means a #define since there is no actual evaluation there[/Edit]

        Regards, Nish


        My technology blog: voidnish.wordpress.com Code Project Forums : New Posts Monitor This application monitors for new posts in the Code Project forums.

        modified on Tuesday, September 28, 2010 1:02 PM

        M Offline
        M Offline
        Mike Doner
        wrote on last edited by
        #3

        Thanks Nish, That did it... I knew it had to be simple. Cheers. M.

        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