예제 #1
0
        private static void MarshalStrings(string s1, out IntPtr p1,
                                           string s2, out IntPtr p2, string s3, out IntPtr p3)
        {
            p1 = p2 = p3 = IntPtr.Zero;

            bool cleanup = true;

            try {
                p1 = UnixMarshal.StringToHeap(s1);
                p2 = UnixMarshal.StringToHeap(s2);
                if (s3 != null)
                {
                    p3 = UnixMarshal.StringToHeap(s3);
                }
                cleanup = false;
            }
            finally {
                if (cleanup)
                {
                    UnixMarshal.FreeHeap(p1);
                    UnixMarshal.FreeHeap(p2);
                    UnixMarshal.FreeHeap(p3);
                }
            }
        }
예제 #2
0
        private static void MarshalStrings(string s1, out IntPtr p1, string s2, out IntPtr p2, string s3, out IntPtr p3)
        {
            IntPtr zero   = IntPtr.Zero;
            IntPtr intPtr = zero;

            p3 = zero;
            IntPtr intPtr1 = intPtr;

            intPtr = intPtr1;
            p2     = intPtr1;
            p1     = intPtr;
            bool flag = true;

            try
            {
                p1 = UnixMarshal.StringToHeap(s1);
                p2 = UnixMarshal.StringToHeap(s2);
                if (s3 != null)
                {
                    p3 = UnixMarshal.StringToHeap(s3);
                }
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    UnixMarshal.FreeHeap((void *)p1);
                    UnixMarshal.FreeHeap((void *)p2);
                    UnixMarshal.FreeHeap((void *)p3);
                }
            }
        }
예제 #3
0
        public static string GetString(string s)
        {
            string str;
            IntPtr heap = UnixMarshal.StringToHeap(s);

            try
            {
                IntPtr intPtr = Catalog.gettext(heap);
                str = (intPtr == heap ? s : UnixMarshal.PtrToStringUnix(intPtr));
            }
            finally
            {
                UnixMarshal.FreeHeap(heap);
            }
            return(str);
        }
예제 #4
0
        public static String GetString(String s)
        {
            IntPtr ints = UnixMarshal.StringToHeap(s);

            try {
                // gettext(3) returns the input pointer if no translation is found
                IntPtr r = gettext(ints);
                if (r != ints)
                {
                    return(UnixMarshal.PtrToStringUnix(r));
                }
                return(s);
            }
            finally {
                UnixMarshal.FreeHeap(ints);
            }
        }
예제 #5
0
 public static IntPtr StringToHeap(string s, int index, int count)
 {
     return(UnixMarshal.StringToHeap(s, index, count, UnixEncoding.Instance));
 }
예제 #6
0
 public static IntPtr StringToHeap(string s, Encoding encoding)
 {
     return(UnixMarshal.StringToHeap(s, 0, s.Length, encoding));
 }
예제 #7
0
 public static IntPtr StringToHeap(string s)
 {
     return(UnixMarshal.StringToHeap(s, UnixEncoding.Instance));
 }