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
Nicholas Paldino [.NET/C# MVP] - 14 Dec 2005 04:52 GMT
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.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Hi,
>
[quoted text clipped - 37 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Virajitha Sarma - 14 Dec 2005 05:18 GMT
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));
Jerry Walter - 14 Dec 2005 20:58 GMT
> Hi,
>
[quoted text clipped - 15 lines]
>
> *** 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.
Willy Denoyette [MVP] - 14 Dec 2005 10:49 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> 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.