By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

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

P: n/a


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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a

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

P: n/a

"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

P: n/a
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.