#defines in C#

  • Thread starter Thread starter Mr.Tickle
  • Start date Start date
M

Mr.Tickle

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#?
 
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.
 
#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.
 
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#?

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
(e-mail address removed)
Anything was possible last night. That was the trouble
with last nights. They were always followed by this mornings.
- Terry Pratchett, "Small Gods"
 
Mr.Tickle said:
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#?

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
 
Back
Top