[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Mr.Tickle

9/16/2003 3:57:00 PM

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


4 Answers

Nicholas Paldino [.NET MVP]

9/16/2003 4:01:00 PM

0

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.paldino@exisconsulting.com

"Mr.Tickle" <MrTickle@mrmen.com> wrote in message
news:uHL3roGfDHA.1748@TK2MSFTNGP10.phx.gbl...
> 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#?
>
>


Morten Wennevik [C# MVP]

9/16/2003 6:09:00 PM

0

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

Jakub Wójciak

9/16/2003 6:18:00 PM

0

> 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
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"

Richard Grimes [MVP]

9/29/2003 4:49:00 PM

0

Mr.Tickle wrote:
> 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
--
my email evpuneqt@zicf.bet is encrypted with ROT13 (www.rot13.org)