471,319 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

difference between uint in C# and DWORD(unsigned long) in c



Hi,

I have a code in C which i am rewritting it in C#.

I am facing problem with the following two lines :

char *cipher;
(DWORD*)cipher(C) and (uint*)cipher(C#) are giving different values
though both DWORD(which is unsigned long) and uint occupy 4 bytes
Why is it happening ? Any insight into this topic would be highly
helpful.

cipher is pointing to
" ;Configurationpage

[InstalledPersonalitiesAndOptions]
Personality=7

[ProductInformation]
ProductName=HP Laser Tablerock
FormatterNumber=HA0001s
PrinterNumber=Q1234A
ProductSerialNumber=XXXXXXXXXX
ServiceID=1001
FirmwareDatecode=0629_07:30:39 Phoenix Firmware
MaxPrintResolution=0
ControllerNumber=1
TeleconVersion=06-015-001
ADFInstalled=1

[EventLog]
NumberEntriesUse=9
MaximumNumberEntries=10

[ProductSettings]
DeviceDescription=HP Laser Tablerock
DeviceLanguage=1"

Thank You

*** Sent via Developersdex http://www.developersdex.com ***
Dec 14 '05 #1
4 12841
Virajitha,

Without knowing what the declaration of the function is, it's impossible
to say. However, you say that a DWORD is an unsigned long. If you are
referring to an unsigned long in C#, then you would be wrong, because that
is an eight byte unsigned value, while a DWORD is a four byte unsigned
value.

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

"Virajitha Sarma" <vi**************@yahoo.com> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...


Hi,

I have a code in C which i am rewritting it in C#.

I am facing problem with the following two lines :

char *cipher;
(DWORD*)cipher(C) and (uint*)cipher(C#) are giving different values
though both DWORD(which is unsigned long) and uint occupy 4 bytes
Why is it happening ? Any insight into this topic would be highly
helpful.

cipher is pointing to
" ;Configurationpage

[InstalledPersonalitiesAndOptions]
Personality=7

[ProductInformation]
ProductName=HP Laser Tablerock
FormatterNumber=HA0001s
PrinterNumber=Q1234A
ProductSerialNumber=XXXXXXXXXX
ServiceID=1001
FirmwareDatecode=0629_07:30:39 Phoenix Firmware
MaxPrintResolution=0
ControllerNumber=1
TeleconVersion=06-015-001
ADFInstalled=1

[EventLog]
NumberEntriesUse=9
MaximumNumberEntries=10

[ProductSettings]
DeviceDescription=HP Laser Tablerock
DeviceLanguage=1"

Thank You

*** Sent via Developersdex http://www.developersdex.com ***

Dec 14 '05 #2

Hi,

Thank you for ur help...

But like DWORD, uint also takes 4 bytes. So I donot think there is any
mismatch in that.

function Declaration in C# :
/unsafe
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_encipher((uint*)ciphPtr , (uint*)(ciphPtr+4) );

in C:
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_encipher((DWORD*)ciphPtr ,(DWORD*)(ciphPtr+4));

*** Sent via Developersdex http://www.developersdex.com ***
Dec 14 '05 #3

"Virajitha Sarma" <vi**************@yahoo.com> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...


Hi,

I have a code in C which i am rewritting it in C#.

I am facing problem with the following two lines :

char *cipher;
(DWORD*)cipher(C) and (uint*)cipher(C#) are giving different values
though both DWORD(which is unsigned long) and uint occupy 4 bytes
Why is it happening ? Any insight into this topic would be highly
helpful.


Not sure what you are trying, posting some real code would help.

char* cipher
is a pointer to a char.
in both C and C# (unsafe context?) you cast cipher to a unsigned int
pointer and you expect that ciper has the same value, right? Wrong, a char
in C is a 8 bit value, while in C# it's a 16bit value. So when you point to
a char from C# and cast the value to an uint, 16 bits will be taken as
source, while when you cast from a char* in C only 8 bits will be taken.
So, in C# you need to consider a C char* as a byte*.

Willy.

Dec 14 '05 #4
On Tue, 13 Dec 2005 21:18:26 -0800, Virajitha Sarma wrote:

Hi,

Thank you for ur help...

But like DWORD, uint also takes 4 bytes. So I donot think there is any
mismatch in that.

function Declaration in C# :
/unsafe
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_encipher((uint*)ciphPtr , (uint*)(ciphPtr+4) );

in C:
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_encipher((DWORD*)ciphPtr ,(DWORD*)(ciphPtr+4));

*** Sent via Developersdex http://www.developersdex.com ***


Maybe, instead of trying to force a token per token translation of the
code, step back and try to understand what is happening, and then proceed
from there.

It looks like you are trying to pass in the memory location of
the begining of the character array and then the memory location of the
4th character in the array ? Is that correct ?

Though this may work, I would suggest that you use the C# language to your advantage, and not try
to force pointer manipulations on the code.

Dec 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

36 posts views Thread by Song Yun Zhao | last post: by
10 posts views Thread by Peter Piper | last post: by
19 posts views Thread by junky_fellow | last post: by
3 posts views Thread by muesliflakes | last post: by
22 posts views Thread by Vijay | last post: by
3 posts views Thread by QQ | last post: by
3 posts views Thread by tutush | last post: by
4 posts views Thread by CedricCicada | last post: by
reply views Thread by rosydwin | last post: by

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.