コード例 #1
0
ファイル: LibPl.cs プロジェクト: segmond/swicli
        public static void LoadUnmanagedLibrary(string fileName)
        {
#if USESAFELIB
            if (m_hLibrary == null)
            {
                if (PrologCLR.IsLinux)
                {
                    return;

                    m_hLibrary = NativeMethodsLinux.LoadLibrary("/lib64/pl-6.0.3/lib/x86_64/libswipl.so");
                    if (m_hLibrary.IsInvalid)
                    {
                        PrologCLR.ConsoleTrace("IsInvalid LoadUnmanagedLibrary " + fileName);
                        // int hr = Marshal.GetHRForLastWin32Error();
                        // Marshal.ThrowExceptionForHR(hr);
                    }
                }
                else
                {
                    m_hLibrary = NativeMethodsWindows.LoadLibrary(fileName);
                    if (m_hLibrary.IsInvalid)
                    {
                        int hr = Marshal.GetHRForLastWin32Error();
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }
            }
#endif
        }
コード例 #2
0
 protected override bool ReleaseHandle()
 {
     if (PrologCLR.IsLinux)
     {
         return(NativeMethodsLinux.FreeLibrary(handle));
     }
     else
     {
         return(NativeMethodsWindows.FreeLibrary(handle));
     }
 }
コード例 #3
0
ファイル: LibPl.cs プロジェクト: segmond/swicli
        public static void SetStreamFunction(Streams.PlStreamType streamType, StreamsFunction functionType, Delegate function)
        {
            //int size_of_IOSTREAM = 136;
            PrologCLR.PinObject(function);
            int size_of_IOSTREAM;
            int offset_to_poninter_of_IOFUNCTIONS;
            int size_of_pointer;

            if (Is64Bit())
            {
                size_of_IOSTREAM = 232;
                offset_to_poninter_of_IOFUNCTIONS = 104;
                size_of_pointer = 8;
            }
            else
            {
                size_of_IOSTREAM = 144;
                offset_to_poninter_of_IOFUNCTIONS = 72;
                size_of_pointer = 4;
            }

#if USESAFELIB
            IntPtr callbackFunctionPtr = Marshal.GetFunctionPointerForDelegate(function);

            IntPtr address_std_stream_array;
            if (PrologCLR.IsLinux)
            {
                address_std_stream_array = NativeMethodsLinux.GetProcAddress(m_hLibrary, "S__iob");
            }
            else
            {
                address_std_stream_array = NativeMethodsWindows.GetProcAddress(m_hLibrary, "S__iob");
            }
            IntPtr function_array_out = Marshal.ReadIntPtr(address_std_stream_array, (size_of_IOSTREAM * (int)streamType) + offset_to_poninter_of_IOFUNCTIONS);

#if false
#if _PL_X64
            Marshal.WriteIntPtr(new IntPtr(function_array_out.ToInt64() + (size_of_pointer * (int)functionType)), callbackFunctionPtr);
#else
            Marshal.WriteIntPtr(new IntPtr(function_array_out.ToInt32() + (size_of_pointer * (int)functionType)), callbackFunctionPtr);
#endif // _PL_X64
#endif // false
            if (Is64Bit())
            {
                Marshal.WriteIntPtr(new IntPtr(function_array_out.ToInt64() + (size_of_pointer * (int)functionType)), callbackFunctionPtr);
            }
            else
            {
                Marshal.WriteIntPtr(new IntPtr(function_array_out.ToInt32() + (size_of_pointer * (int)functionType)), callbackFunctionPtr);
            }
#endif // USESAFELIB
        }