#defines in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mr.Tickle

    #defines in C#

    I have a .H file with tonnes of #define constants and I want to access that
    from C# but I dont want to rewrite the header file as a class.


    Is there a way after including that in MC++ to get those values from C#?


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: #defines in C#

    Mr.Tickle,

    Even if you include it in a MC++ project, you still will have to
    redefine the define statements with the constants.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
    news:uHL3roGfDH A.1748@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I have a .H file with tonnes of #define constants and I want to access[/color]
    that[color=blue]
    > from C# but I dont want to rewrite the header file as a class.
    >
    >
    > Is there a way after including that in MC++ to get those values from C#?
    >
    >[/color]


    Comment

    • Morten Wennevik

      #3
      Re: #defines in C#

      #define in C# is either true or false, you can define numbers. So even if
      you managed to include the #defines without rewriting them, most likely you
      would get unacceptable errors.

      --
      Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

      Comment

      • Jakub Wójciak

        #4
        Re: #defines in C#

        > I have a .H file with tonnes of #define constants and I want to access
        that[color=blue]
        > from C# but I dont want to rewrite the header file as a class.
        > Is there a way after including that in MC++ to get those values from C#?[/color]

        Create a simple parser that will do this automatically for you. That way,
        when you change the original .h file, you can automatically get a new class
        for .NET - you can even integrate it as a custom build step.
        Remember the golden rule of programming: DRY - Don't Repeat Yourself!

        --
        pozdrawia
        qbeuek@zdnet.pl
        Anything was possible last night. That was the trouble
        with last nights. They were always followed by this mornings.
        - Terry Pratchett, "Small Gods"

        Comment

        • Richard Grimes [MVP]

          #5
          Re: #defines in C#

          Mr.Tickle wrote:[color=blue]
          > I have a .H file with tonnes of #define constants and I want to
          > access that from C# but I dont want to rewrite the header file as a
          > class.
          >
          > Is there a way after including that in MC++ to get those values from
          > C#?[/color]

          There are several issues. If you use managed C++ to get the manifest
          constants into an assembly you are relying on the C preprocessor to paste
          values into your code, for example if you have:

          #define SIZE 45

          then whenever your code uses SIZE the C preprocessor will insert the value
          of 45 before the code is compiled. The constant is not available to any
          other code unless you write that code in managed C++ and include the header.
          So those constants will not be available to your C# code.

          Also, the technique is not object orientated. It is better to copy the
          constants into your C# class as a const field, that way the constant is
          associated with the code that will use it.

          Richard
          --
          my email evpuneqt@zicf.b et is encrypted with ROT13 (www.rot13.org)


          Comment

          Working...