public static float ReadSingle(IntPtr from, int offset) { SingleToInt sti = new SingleToInt(); sti.theInt = Marshal.ReadInt32(from, offset); return(sti.theSingle); }
public static void Write(IntPtr to, int offset, float from) { SingleToInt sti = new SingleToInt(); sti.theSingle = from; Marshal.WriteInt32(to, offset, sti.theInt); }
public static float ReadSingle(IntPtr from, int offset) { SingleToInt sti = new SingleToInt(); sti.theInt = Marshal.ReadInt32(from, offset); return sti.theSingle; }
public void CopyOut(IntPtr gapiPtr, int offset) { foreach (KeyValuePair <int, PropertyInvoker <short> > keyVal in propertyContainer.Int16Properties) { keyVal.Value.Set(Marshal.ReadInt16(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <ushort> > keyVal in propertyContainer.UInt16Properties) { keyVal.Value.Set((ushort)Marshal.ReadInt16(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <int> > keyVal in propertyContainer.Int32Properties) { keyVal.Value.Set(Marshal.ReadInt32(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <uint> > keyVal in propertyContainer.UInt32Properties) { keyVal.Value.Set((uint)Marshal.ReadInt32(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <long> > keyVal in propertyContainer.Int64Properties) { keyVal.Value.Set(Marshal.ReadInt64(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <ulong> > keyVal in propertyContainer.UInt64Properties) { keyVal.Value.Set((ulong)Marshal.ReadInt64(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <float> > keyVal in propertyContainer.SingleProperties) { //IntPtr newPtr = new IntPtr(gapiPtr.ToInt64() + offset + keyVal.Key); //keyVal.Value.Set((float)Marshal.PtrToStructure(newPtr, typeof(float))); SingleToInt sti = new SingleToInt(); sti.theInt = Marshal.ReadInt32(gapiPtr, offset + keyVal.Key); keyVal.Value.Set(sti.theSingle); } foreach (KeyValuePair <int, PropertyInvoker <double> > keyVal in propertyContainer.DoubleProperties) { //IntPtr newPtr = new IntPtr(gapiPtr.ToInt64() + offset + keyVal.Key); //keyVal.Value.Set((double)Marshal.PtrToStructure(newPtr, typeof(double))); DoubleToLong dtl = new DoubleToLong(); dtl.theLong = Marshal.ReadInt64(gapiPtr, offset + keyVal.Key); keyVal.Value.Set(dtl.theDouble); } foreach (KeyValuePair <int, PropertyInvoker <byte> > keyVal in propertyContainer.ByteProperties) { keyVal.Value.Set(Marshal.ReadByte(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <char> > keyVal in propertyContainer.CharProperties) { keyVal.Value.Set((char)Marshal.ReadByte(gapiPtr, offset + keyVal.Key)); } foreach (KeyValuePair <int, PropertyInvoker <string> > keyVal in propertyContainer.StringProperties) { IntPtr stringPtr = Marshal.ReadIntPtr(gapiPtr, offset + keyVal.Key); keyVal.Value.Set(Marshal.PtrToStringAnsi(stringPtr)); } foreach (KeyValuePair <int, PropertyInvoker <bool> > keyVal in propertyContainer.BoolProperties) { keyVal.Value.Set(Marshal.ReadByte(gapiPtr, offset + keyVal.Key) != 0); } // array type[] to gapi sequence<type> // jagged array type[][] to gapi sequence<sequence<type>> // fixed array type[] to gapi type[n] // multi-dim array type[,] to gapi type[][] // union }
public void CopyIn(IntPtr gapiPtr, int offset) { // short to gapi int foreach (KeyValuePair <int, PropertyInvoker <short> > keyVal in propertyContainer.Int16Properties) { Marshal.WriteInt16(gapiPtr, offset + keyVal.Key, keyVal.Value.Get()); } // ushort to gapi unsigned int foreach (KeyValuePair <int, PropertyInvoker <ushort> > keyVal in propertyContainer.UInt16Properties) { Marshal.WriteInt16(gapiPtr, offset + keyVal.Key, (short)keyVal.Value.Get()); } // int to gapi long foreach (KeyValuePair <int, PropertyInvoker <int> > keyVal in propertyContainer.Int32Properties) { Marshal.WriteInt32(gapiPtr, offset + keyVal.Key, keyVal.Value.Get()); } // uint to gapi unsigned long foreach (KeyValuePair <int, PropertyInvoker <uint> > keyVal in propertyContainer.UInt32Properties) { Marshal.WriteInt32(gapiPtr, offset + keyVal.Key, (int)keyVal.Value.Get()); } // long to gapi long long foreach (KeyValuePair <int, PropertyInvoker <long> > keyVal in propertyContainer.Int64Properties) { Marshal.WriteInt64(gapiPtr, offset + keyVal.Key, keyVal.Value.Get()); } // ulong to gapi unsigned long long foreach (KeyValuePair <int, PropertyInvoker <ulong> > keyVal in propertyContainer.UInt64Properties) { Marshal.WriteInt64(gapiPtr, offset + keyVal.Key, (long)keyVal.Value.Get()); } // float foreach (KeyValuePair <int, PropertyInvoker <float> > keyVal in propertyContainer.SingleProperties) { // floats are actually Struct Single // IntPtr doesn't allow pointer arithmetic, so convert to long and add //IntPtr newPtr = new IntPtr(gapiPtr.ToInt64() + offset + keyVal.Key); //Marshal.StructureToPtr(keyVal.Value.Get(), newPtr, true); SingleToInt sti = new SingleToInt(); sti.theSingle = keyVal.Value.Get(); Marshal.WriteInt32(gapiPtr, offset + keyVal.Key, sti.theInt); } // double foreach (KeyValuePair <int, PropertyInvoker <double> > keyVal in propertyContainer.DoubleProperties) { // doubles are actually Struct Double // IntPtr doesn't allow pointer arithmetic, so convert to long and add //IntPtr newPtr = new IntPtr(gapiPtr.ToInt64() + offset + keyVal.Key); //Marshal.StructureToPtr(keyVal.Value.Get(), newPtr, true); DoubleToLong dtl = new DoubleToLong(); dtl.theDouble = keyVal.Value.Get(); Marshal.WriteInt64(gapiPtr, offset + keyVal.Key, dtl.theLong); } // byte to gapi octet foreach (KeyValuePair <int, PropertyInvoker <byte> > keyVal in propertyContainer.ByteProperties) { Marshal.WriteByte(gapiPtr, offset + keyVal.Key, keyVal.Value.Get()); } // char to gapi char (only 1 byte) foreach (KeyValuePair <int, PropertyInvoker <char> > keyVal in propertyContainer.CharProperties) { // Only use the lower 8 bits or lower byte. Marshal.WriteByte(gapiPtr, offset + keyVal.Key, (byte)keyVal.Value.Get()); } // string to gapi string foreach (KeyValuePair <int, PropertyInvoker <string> > keyVal in propertyContainer.StringProperties) { IntPtr stringPtr = Marshal.StringToHGlobalAnsi(keyVal.Value.Get()); Marshal.WriteIntPtr(gapiPtr, offset + keyVal.Key, stringPtr); } // bool foreach (KeyValuePair <int, PropertyInvoker <bool> > keyVal in propertyContainer.BoolProperties) { Marshal.WriteByte(gapiPtr, offset + keyVal.Key, keyVal.Value.Get() ? (byte)1 : (byte)0); } // array type[] to gapi sequence<type> // jagged array type[][] to gapi sequence<sequence<type>> // fixed array type[] to gapi type[n] // multi-dim array type[,] to gapi type[][] // union }