473,397 Members | 2,056 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,397 software developers and data experts.

how to realize "#define" macro definition in C#


I have such a block in C++
#pragma pack(push,4)
#define STATE_NULL 0x0000
#pragma pack(pop)

and I need to convert it to C#.

I want to use the "MarshalAs" attribute, but i dont
know which UnmanagedType that hex value belongs to.

Is there another way to realize this convertion ?

thank you very muc

--
xudeutschPosted from http://www.pcreview.co.uk/ newsgroup acces

Nov 17 '05 #1
3 14432
xudeutsch,

You should use a constant for this, like so:

public const int STATE_NULL = 0;

C# does not use pre-processor defines to perform replacement in code, so
you have to use a constant.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"xudeutsch" <xudeutsch.1re30c@> wrote in message
news:zM********************@giganews.com...

I have such a block in C++
#pragma pack(push,4)
#define STATE_NULL 0x0000
#pragma pack(pop)

and I need to convert it to C#.

I want to use the "MarshalAs" attribute, but i dont
know which UnmanagedType that hex value belongs to.

Is there another way to realize this convertion ?

thank you very much
--
xudeutschPosted from http://www.pcreview.co.uk/ newsgroup access

Nov 17 '05 #2
what about simply

const int StateNull = 0x0000;

"xudeutsch" <xudeutsch.1re30c@> schrieb im Newsbeitrag
news:zM********************@giganews.com...

I have such a block in C++
#pragma pack(push,4)
#define STATE_NULL 0x0000
#pragma pack(pop)

and I need to convert it to C#.

I want to use the "MarshalAs" attribute, but i dont
know which UnmanagedType that hex value belongs to.

Is there another way to realize this convertion ?

thank you very much
--
xudeutschPosted from http://www.pcreview.co.uk/ newsgroup access

Nov 17 '05 #3

thanks, Nicholas and cody.
but as far as i know, the following directive
" #pragma pack(push,4)"
will ensure that: when the data are transferred through
networks to other platforms, the const value "STATE_NULL"
will still be regarded as a 4-byte value in the stack,
namely 0x0000. I dont know whether other statements are
needed or it is default that on every machine this hex value will
be treated as 4-byte. Is that not in 2-byte?

thanks a lot

--
xudeutschPosted from http://www.pcreview.co.uk/ newsgroup acces

Nov 17 '05 #4

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

Similar topics

2
by: Chris Hodapp | last post by:
I have seen messages posted about this before, and there is a clear reference to it in the manual, but I have been unable to find a solution. I'm on Slackware 9.1, kernel 2.6.0-test11, using...
20
by: Dead RAM | last post by:
Hey people, i'll try to keep this short ;) Here is what I want to type (or at least close too)... #define VER_BUILD 1 #define STR_VER_BUILD "VER_BUILD" But what happends is...
4
by: xudeutsch | last post by:
thanks, Nicholas and cody. but as far as i know, the following directive " #pragma pack(push,4)" will ensure that: when the data are transferred through networks to other platforms, the const...
1
by: James | last post by:
Hi all, How do you #define (as in C++) in C#? Many thanks, James
5
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base...
4
by: paapa21 | last post by:
I want to Declear a variable as SqlDataReader in ASP 2.0. But when i do so it tells me SqlDataReader is not define. This same code works in my previous application in ASP 1.0. Has this change? Can...
14
by: Chen Shusheng | last post by:
CSS white here: Simply strange, I found "define" can not work with "malloc". Together my complier will say "parse error". Could anyone tell me why? ------------------------- #define MAX 10000...
17
by: Chen Shusheng | last post by:
Hi all, In fact, I want to let my memory run out. And see what will happen. My system is windowsXp. Memory is 256M.I think my cdes will apply more memory than I have. Codes are below: ...
2
by: slrj | last post by:
Can someone explain me what's going on in the code below. As per my knowledge "#define <macro name> <Macro replacement>" doesn't have a semicolon and it's terminated by a new line. But the code line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.