Re: RtlMoveMemory to read an integer from a file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Bill Mittenzwey (bmittenzwey)
Date: 03/10/04


Date: Wed, 10 Mar 2004 09:24:31 -0600

Thanks to both posts. That really simplifies things.

"Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.com> wrote
in message news:eNBt6hoBEHA.4080@TK2MSFTNGP09.phx.gbl...
> You can also use a BinaryReader's ReadInt32 or ReadInt16 method if you
need
> to read an int. There are also ReadDouble and ReadDecimal methods.
>
> --
> Dmitriy Lapshin [C# / .NET MVP]
> X-Unity Test Studio
> http://www.x-unity.net/teststudio.aspx
> Bring the power of unit testing to VS .NET IDE
>
> "Bill Mittenzwey gateway edi.com>" <bmittenzwey<ATremove space> wrote in
> message news:OjdbWdiBEHA.3360@TK2MSFTNGP11.phx.gbl...
> > 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;
> >
> > }
> >
> >
> >
> >
> >
> >
>



Relevant Pages

  • [RFC] Fix Device Power Management States
    ... the patch below attempts to fix up the device power management ... This is implemented by iterating through the list of struct classes, ... +int class_dev_start ... +extern int device_power_default; ...
    (Linux-Kernel)
  • Re: How to power off on WM5 Pocket PC of HTC?
    ... For WM5.0 you should use the supported ExitWindowsEx method. ... static extern int SetSystemPowerState(string psState, int StateFlags, ... I want to use KernelIoControl function to power off device,but I don't ...
    (microsoft.public.pocketpc.developer)
  • Re: While loop issue.
    ... @Voltage int, ... return @qty ... Since the Power of the transformer I am using is 4200 qty should =3. ... the while loop once. ...
    (microsoft.public.sqlserver.server)
  • [PATCH 5/13] ACPI / PM: Introduce function for refcounting device power resources
    ... Introduce function acpi_power_on_resourcesthat reference counts ... a given power state of it. ... int enable, int sleep_state, int dev_state); ...
    (Linux-Kernel)
  • Re: minimum and maximum values of an object of type int
    ... may have a higher absolute value, ... An int must comprise one sign bit, at least fifteen value bits (but ... be exactly one less than a power of two. ... because padding bits contribute to the size of the int. ...
    (comp.lang.c)