473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

#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#?
Nov 15 '05 #1
4 1257
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]
- ni**************@exisconsulting.com

"Mr.Tickle" <Mr******@mrmen.com> wrote in message
news:uH**************@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#?

Nov 15 '05 #2
#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/
Nov 15 '05 #3
> 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
qb****@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"

Nov 15 '05 #4
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 ev******@zicf.bet is encrypted with ROT13 (www.rot13.org)
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mr.Tickle | last post by:
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...
4
by: Pelle Beckman | last post by:
Hi, I saw this code in an earlier post (not that there's anything wrong with it) #include <iostream> using std::cout; const int hour = 3600; const int min = 60;
2
by: Pelle Beckman | last post by:
Hi, This might be OT... Are there preprocessor defines in the C++ standard, such as __FILE__, __LINE__, __NAMESPACE__, __FUNCTION__, ec? If there is, were can I find a list? If there...
3
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
7
by: John Dolinka | last post by:
I have a project of several files with #defines to setup a conditional compile. I would like to put these #defines in a single file and change the conditional compile from this one file with the...
0
by: Ram Patel | last post by:
Hello, I have problem with Atlas XML script which defines behavior to tables for drag and drop like below: <script id="script1" type="text/xml-script"> <page > <components> <control...
6
by: Richard | last post by:
1. Are there any problems with having, for instance, POSIX's "open" function #defined more than once. In my case, these would be in different static libraries: #ifdef __cplusplus extern "C" {...
7
by: raghu | last post by:
Hello Everyone, I am using macro functions in my project the code is working correctly, But I have a doubt wheather the macro functions creates a context switching as in the case of normal...
2
by: =?Utf-8?B?VGhlQ3VyaW91c09uZQ==?= | last post by:
I have this situation where I need to access the #defines and typedefs defined in a C++ header file from a .NET Project (specifically C#). The C++ header file is from a medical device manufacturer...
14
by: Eliot | last post by:
I have a project which may be compiled with some #defines. Say:- #define firstdef #define seconddef If no defines are present or only one is present all is OK. I would like to add a self...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.