how to read .h file in C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: how to read .h file in C#

  1. #1
    Join Date
    May 2011
    Posts
    3

    how to read .h file in C#

    I have one .Net assembly which includes native .h files as a link. The .h file is placed at a common loaction and used across projects (C++ and C#).
    These header files have some structures and #define in it.
    In my .Net assembly i have defined structures and doing marshalling using Interop services and is working fine. For #define also, i defined
    variables in .Net assembly and setting the value, something like:

    C++ .h file

    #define MyValue 0x100

    C# assembly

    internal class MyClass
    {
    protected const MyValue = 0x100;
    }

    But with such code, i need to update MyValue in C# assembly everytime it gets modified in .h file. And generally in my project, the
    structures in this .h file are not changed but the #define variable gets modified often.
    Is there any way, that allows me
    to set this variable directly from .h file, something like:

    internal class MyClass
    {
    protected const MyValue = MyValue (from .h file);
    }

    i.e. is it possible to read .h file in C# assembly? Please let me know some ideas for the above problem.

  2. #2
    Join Date
    Mar 2004
    Location
    3311'18.10"N 9645'20.28"W
    Posts
    1,808

    Re: how to read .h file in C#

    no. when you update your header files, update your C# interop files too.

    the only way to update your C# interop files would be to create a pre-build event that parsed your header files and (deleted the existing C# file and) generated your C# files on every build.

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: how to read .h file in C#

    Is using COM an option here? You are basically manually doing what COM can do for you by exposing types and structures defined in the native dll (#defines will still be an issue though). If you can't go the COM route then yes, you will need to parse the files when they change, preferably in an automated fashion as MadHatter suggested.

  4. #4
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: how to read .h file in C#

    Using T4 for this may be a good idea?

    Whenever the C++'s .h file changes, simply re-run the T4 to recreate the C# bits.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center