Page 1 of 1

C# - Cast Error

Posted: Mon Aug 25, 2008 9:59 pm
by grimdoomer
Well I'm working on a RealTimeHalo system for halo 2 vista. I made a Memory Reading/Writing class. But when ever I try to convert a byte array to any other data type, I get an exception that says Unable to cast type "byte[]" to "IConvertable".
I know this conversion works, I've used it in the past. Here is an example:

Code: Select all

        public float ReadSingle(int Address)
        {
            byte[] buffer = new byte[4];
            ReadProcessMemory(m_hProcess, new IntPtr(Address + baseaddress), buffer, 4, out Out);
            return Convert.ToSingle(buffer);
        }
Any ideas?

Re: C# - Cast Error

Posted: Mon Aug 25, 2008 10:22 pm
by LuxuriousMeat
grimdoomer wrote:Well I'm working on a RealTimeHalo system for halo 2 vista. I made a Memory Reading/Writing class. But when ever I try to convert a byte array to any other data type, I get an exception that says Unable to cast type "byte[]" to "IConvertable".
I know this conversion works, I've used it in the past. Here is an example:

Code: Select all

        public float ReadSingle(int Address)
        {
            byte[] buffer = new byte[4];
            ReadProcessMemory(m_hProcess, new IntPtr(Address + baseaddress), buffer, 4, out Out);
            return Convert.ToSingle(buffer);
        }
Any ideas?

Code: Select all

return BitConverter.ToSingle(buffer, 0);

Posted: Mon Aug 25, 2008 11:24 pm
by grimdoomer
Thanks soo much! :D

Posted: Wed Aug 27, 2008 8:16 am
by LuxuriousMeat
grimdoomer wrote:Thanks soo much! :D
No problem :).