B
Bill Mittenzwey
I am trying to read a string of bytes out of a file and convert them into an
int. I can make it work in Visual Fox (see below), but I can't seem to get
the same code to work in c# (see below the fox sample).
Does anyone recognize this or can anyone let me know what I am doing wrong?
Is there a better way than the WinAPI?
in fox I can do this:
declare VOID RtlMoveMemory in win32api Double @Dest, Char @Src, Size_T
BytesToCopy
c = CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0x80) + CHR(0x50)+
CHR(0x40)
VariableDecimals= 0
*This will round to 0 decimals.
set decimals to (VariableDecimals)
VariableValue = 10^(-VariableDecimals)
VariableLength = 8
=RtlMoveMemory(@VariableValue, @c, VariableLength )
The value of VariableValue will be 66
In c#:
At the top of the class:
[DllImport("kernel32.dll")]
public static extern void RtlMoveMemory(ref double dest, ref string src,
long bytesToCopy);
public static decimal convertNumber(string strValue, int varDec)
{
double varValue = Math.Pow(10,-1*varDec);
int varLen = 8;
RtlMoveMemory(ref varValue, ref strValue, varLen);
decimal outVal = Convert.ToDecimal(Math.Round(varValue,varDec));
return outVal;
}
int. I can make it work in Visual Fox (see below), but I can't seem to get
the same code to work in c# (see below the fox sample).
Does anyone recognize this or can anyone let me know what I am doing wrong?
Is there a better way than the WinAPI?
in fox I can do this:
declare VOID RtlMoveMemory in win32api Double @Dest, Char @Src, Size_T
BytesToCopy
c = CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0x80) + CHR(0x50)+
CHR(0x40)
VariableDecimals= 0
*This will round to 0 decimals.
set decimals to (VariableDecimals)
VariableValue = 10^(-VariableDecimals)
VariableLength = 8
=RtlMoveMemory(@VariableValue, @c, VariableLength )
The value of VariableValue will be 66
In c#:
At the top of the class:
[DllImport("kernel32.dll")]
public static extern void RtlMoveMemory(ref double dest, ref string src,
long bytesToCopy);
public static decimal convertNumber(string strValue, int varDec)
{
double varValue = Math.Pow(10,-1*varDec);
int varLen = 8;
RtlMoveMemory(ref varValue, ref strValue, varLen);
decimal outVal = Convert.ToDecimal(Math.Round(varValue,varDec));
return outVal;
}