Esempio n. 1
0
        public static string getenv(string name)
        {
            IntPtr r = sys_getenv(name);

            return(UnixMarshal.PtrToString(r));
        }
Esempio n. 2
0
 object ICustomMarshaler.MarshalNativeToManaged(IntPtr pNativeData)
 {
     return(UnixMarshal.PtrToString(pNativeData, UnixEncoding.Instance));
 }
Esempio n. 3
0
 /// <summary>
 /// Gets a value for a key from the infobuffer
 /// </summary>
 /// <param name="key">
 /// The key <see cref="System.String"/>
 /// </param>
 /// <returns>
 /// The value <see cref="System.String"/>
 /// </returns>
 public string Get(string key)
 {
     return(UnixMarshal.PtrToString(MetaModEngine.engineFunctions.InfoKeyValue(
                                        MetaModEngine.engineFunctions.GetInfoKeyBuffer(Pointer),
                                        key)));
 }
        // Disable the following warning for netcore builds:
        //
        //  Nullability of reference types in return type of 'object? FileNameMarshaler.MarshalNativeToManaged(IntPtr pNativeData)' doesn't match implicitly implemented member 'object ICustomMarshaler.MarshalNativeToManaged(IntPtr pNativeData)' (possibly because of nullability attributes).
        //
        // We should return `null` for IntPtr.Zero but the ICustomMarshaler class doesn't have NRT annotations, so
        // instead of throwing an exception we are better off ignoring the compile warning
        //
#if NETCOREAPP
#pragma warning disable 8766
#endif // NETCOREAPP
        public object?MarshalNativeToManaged(IntPtr pNativeData)
        {
            return(UnixMarshal.PtrToString(pNativeData, UnixEncoding.Instance));
        }
Esempio n. 5
0
        public void TestUtf32PtrToString()
        {
            var utf32NativeEndianNoBom = new UTF32Encoding(
                bigEndian: !BitConverter.IsLittleEndian,
                byteOrderMark: false,
                throwOnInvalidCharacters: true
                );

            // assemble a buffer that contains:
            // 1. eight garbage bytes
            // 2. the native-endian UTF-32 string "Hello, World" without BOM
            // 3. four 0 bytes (as a C wide string terminator)
            // 4. the native-endian UTF-32 string "broken" without BOM
            // 5. eight 0 bytes
            // 6. four garbage bytes
            var buf = new List <byte>();

            for (int i = 0; i < 2; ++i)
            {
                buf.Add((byte)0x12);
                buf.Add((byte)0x34);
                buf.Add((byte)0x56);
                buf.Add((byte)0x78);
            }

            buf.AddRange(utf32NativeEndianNoBom.GetBytes("Hello, World"));

            for (int i = 0; i < 4; ++i)
            {
                buf.Add((byte)0x00);
            }

            buf.AddRange(utf32NativeEndianNoBom.GetBytes("broken"));

            for (int i = 0; i < 8; ++i)
            {
                buf.Add((byte)0x00);
            }

            buf.Add((byte)0x12);
            buf.Add((byte)0x34);
            buf.Add((byte)0x56);
            buf.Add((byte)0x78);

            // get the array version of this
            var bufArr = buf.ToArray();

            // allocate a buffer that will contain this string
            IntPtr bufPtr = UnixMarshal.AllocHeap(bufArr.Length);
            string returned;

            try
            {
                // copy it in
                Marshal.Copy(bufArr, 0, bufPtr, bufArr.Length);

                // try getting it back
                returned = UnixMarshal.PtrToString(bufPtr + 8, utf32NativeEndianNoBom);
            }
            finally
            {
                UnixMarshal.FreeHeap(bufPtr);
            }

            Assert.AreEqual("Hello, World", returned);
        }
Esempio n. 6
0
 public object MarshalNativeToManaged(IntPtr
                                      pNativeData)
 {
     return(UnixMarshal.PtrToString(pNativeData,
                                    Encoding.UTF32));
 }
Esempio n. 7
0
File: Hid.cs Progetto: mru00/hidapi
 public object MarshalNativeToManaged(IntPtr pNativeData)
 {
     Console.WriteLine("i was ere");
     return(UnixMarshal.PtrToString(pNativeData, Encoding.UTF32));
 }
Esempio n. 8
0
 public static string getenv(string name)
 {
     return(UnixMarshal.PtrToString(Stdlib.sys_getenv(name)));
 }