473,473 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

#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#?
Jul 21 '05 #1
4 6008
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#?

Jul 21 '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/
Jul 21 '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"

Jul 21 '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)
Jul 21 '05 #5

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

Similar topics

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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.