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. C#
  4. C #define to C# constant converstion tool

C #define to C# constant converstion tool

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studiotoolshelp
9 Posts 4 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
    mbender
    wrote on last edited by
    #1

    I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike

    S P R 3 Replies Last reply
    0
    • M mbender

      I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike

      S Offline
      S Offline
      saurabh sahay
      wrote on last edited by
      #2

      You can use the utility MSBuild Task[^] that provides the code that runs during the build process. You need to include the code to convert header file #define to C# constant

      1 Reply Last reply
      0
      • M mbender

        I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I use the C pre-processor and then pass the result to CSC. But I don't know about integrating that with VS. One of the problems with trying to automatically convert it is that the macroes don't specify a type. Another solution would be to store the items in XML and then use XSLT to produce either C/C++ (h) or C# code as required.

        M 1 Reply Last reply
        0
        • M mbender

          I am looking at a series of header files with thousands of #define statements in them. I have been tasked with writing a utility that utilizes these defines in C#. I know that I can manually convert these, but unfortunately they are living files and I would have a maintenance nightmare. My question is does anyone have or used any utilities that can be run has a pre-build process from inside VS that converts header file #define to C# constant? Any help on this is greatly appreciated! ~Mike

          R Offline
          R Offline
          Rob Philpott
          wrote on last edited by
          #4

          Yeah, tricky. Interesting problem too. I guess you're right, have a prebuild step which parses the #defines and spits out constant integers. I know of no such tool, but should be easy to write yourself. I've got some vague recollection that .NET doesn't stash constant integers in metadata but resolves them to numbers during main compilation. If this is correct, if your constants are used outside the assembly they're defined in, you'd need to rebuild that assembly as well. Just replacing the one assembly don't work. Perhaps someone here could confirm that or tell me I dreamt it.

          Regards, Rob Philpott.

          1 Reply Last reply
          0
          • P PIEBALDconsult

            I use the C pre-processor and then pass the result to CSC. But I don't know about integrating that with VS. One of the problems with trying to automatically convert it is that the macroes don't specify a type. Another solution would be to store the items in XML and then use XSLT to produce either C/C++ (h) or C# code as required.

            M Offline
            M Offline
            mbender
            wrote on last edited by
            #5

            Interesting idea...I have a question as to what and how you pass data from the C pre-processor to the CSC? Thanks everyone for you thoughts!

            P 1 Reply Last reply
            0
            • M mbender

              Interesting idea...I have a question as to what and how you pass data from the C pre-processor to the CSC? Thanks everyone for you thoughts!

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              "C:\mingw\bin\cpp" -P -C -w %1.cs %1.csi csc.exe @"C:\batfiles\Build.rsp" %1.csi

              M 1 Reply Last reply
              0
              • P PIEBALDconsult

                "C:\mingw\bin\cpp" -P -C -w %1.cs %1.csi csc.exe @"C:\batfiles\Build.rsp" %1.csi

                M Offline
                M Offline
                mbender
                wrote on last edited by
                #7

                Thanks PIEBALDconsult...Couple questions 1. Is this entered at the command-line or via a batch file? 2. The "C:\mingw\bin\cpp" reference. Where is this from? Thanks again!

                P 1 Reply Last reply
                0
                • M mbender

                  Thanks PIEBALDconsult...Couple questions 1. Is this entered at the command-line or via a batch file? 2. The "C:\mingw\bin\cpp" reference. Where is this from? Thanks again!

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  Those are part of my CC.BAT file. http://www.mingw.org/[^] I'm trying to remember where I got the installer I used, at the moment I can't even find the file I downloaded. Ah, I remember; at one point I had installed Quincy[^] and it installed MinGW. When I built my current system I simply copied the directory tree over.

                  modified on Thursday, June 11, 2009 2:58 PM

                  M 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Those are part of my CC.BAT file. http://www.mingw.org/[^] I'm trying to remember where I got the installer I used, at the moment I can't even find the file I downloaded. Ah, I remember; at one point I had installed Quincy[^] and it installed MinGW. When I built my current system I simply copied the directory tree over.

                    modified on Thursday, June 11, 2009 2:58 PM

                    M Offline
                    M Offline
                    mbender
                    wrote on last edited by
                    #9

                    Thanks..I will look into this

                    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