Example #1
0
        public IntPtr MarshalManagedToNative(object obj)
        {
            if (obj == null)
            {
                return(IntPtr.Zero);
            }
            byte[] bytes = Encoding.UTF8.GetBytes((string)obj);
            IntPtr mem   = MDL.Alloc(bytes.Length + 1);

            Marshal.Copy(bytes, 0, mem, bytes.Length);
            Marshal.WriteByte(mem, bytes.Length, 0);
            return(mem);
        }
Example #2
0
        public static IntPtr AllocInterface(NI.ObjInterface iftemplate, string name)
        {
            byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name);

            IntPtr iface = MDL.Alloc(NI.ObjInterfaceSize + nameBytes.Length + 1);

            IntPtr nameOffset = (IntPtr)(iface.ToInt64() + NI.ObjInterfaceSize);

            iftemplate.name = nameOffset;

            Marshal.StructureToPtr(iftemplate, iface, false);
            Marshal.Copy(nameBytes, 0, nameOffset, nameBytes.Length);
            Marshal.WriteByte(nameOffset, nameBytes.Length, 0);

            return(iface);
        }
Example #3
0
 public static IntPtr DefaultMemFunc(IntPtr ud, IntPtr ptr, IntPtr size)
 {
     if (ptr != IntPtr.Zero && size != IntPtr.Zero)
     {
         return(MDL.Realloc(ptr, size));
     }
     else if (size != IntPtr.Zero)
     {
         return(MDL.Alloc(size));
     }
     if (ptr != IntPtr.Zero)
     {
         MDL.Free(ptr);
     }
     return(IntPtr.Zero);
 }