Exemplo n.º 1
0
        /// <summary>
        /// Retrieves a list of available ELS platform-supported services, along with associated
        /// information, according to application-specified criteria.
        /// </summary>
        /// <param name="options">Optional. A <see cref="MappingEnumOptions">MappingEnumOptions</see> object containing criteria to use during
        /// enumeration of services. The application specifies null for this parameter to retrieve all
        /// installed services.</param>
        /// <returns>An array of <see cref="MappingService">MappingService</see> objects matching the criteria supplied in the options
        /// parameter.</returns>
        public static MappingService[] GetServices(MappingEnumOptions options)
        {
            ThrowIfNotWin7();

            IntPtr servicePointer = IntPtr.Zero;
            UInt32 serviceCount   = 0;
            UInt32 hresult        = 0;
            IntPtr guidPointer    = IntPtr.Zero;

            try
            {
                if (options != null)
                {
                    Win32EnumOptions enumOptions = options._win32EnumOption;
                    Nullable <Guid>  pGuid       = options._guid;
                    if (pGuid != null)
                    {
                        Guid guid = (Guid)pGuid;
                        guidPointer = Marshal.AllocHGlobal(InteropTools.SizeOfGuid);
                        Marshal.StructureToPtr(guid, guidPointer, false);
                        enumOptions._pGuid = guidPointer;
                    }
                    hresult = Win32NativeMethods.MappingGetServices(ref enumOptions, ref servicePointer, ref serviceCount);
                }
                else
                {
                    hresult = Win32NativeMethods.MappingGetServices(IntPtr.Zero, ref servicePointer, ref serviceCount);
                }

                if (hresult != 0)
                {
                    throw new LinguisticException(hresult);
                }
                if ((servicePointer == IntPtr.Zero) != (serviceCount == 0))
                {
                    throw new InvalidOperationException();
                }

                IntPtr[] services = new IntPtr[serviceCount];
                ServiceCache.Instance.RegisterServices(ref servicePointer, services);
                MappingService[] result = new MappingService[serviceCount];
                for (int i = 0; i < serviceCount; ++i)
                {
                    result[i] = new MappingService(services[i]);
                }
                return(result);
            }
            finally
            {
                if (servicePointer != IntPtr.Zero)
                {
                    // Ignore the result if an exception is being thrown.
                    Win32NativeMethods.MappingFreeServicesVoid(servicePointer);
                }
                if (guidPointer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(guidPointer);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a list of available ELS platform-supported services, along with associated
        /// information, according to application-specified criteria.
        /// </summary>
        /// <param name="options">Optional. A <see cref="MappingEnumOptions">MappingEnumOptions</see> object containing criteria to use during
        /// enumeration of services. The application specifies null for this parameter to retrieve all
        /// installed services.</param>
        /// <returns>An array of <see cref="MappingService">MappingService</see> objects matching the criteria supplied in the options
        /// parameter.</returns>
        public static MappingService[] GetServices(MappingEnumOptions options)
        {
            // Throw PlatformNotSupportedException if not running on Win7 or greater
            ThrowIfNotWin7();

            IntPtr pService       = IntPtr.Zero;
            UInt32 dwServiceCount = 0;
            UInt32 hResult        = 0;
            IntPtr guidPtr        = IntPtr.Zero;

            try
            {
                if (options != null)
                {
                    Win32EnumOptions enumOptions = options._win32EnumOption;
                    Nullable <Guid>  pGuid       = options._guid;
                    if (pGuid != null)
                    {
                        Guid guid = (Guid)pGuid;
                        guidPtr = Marshal.AllocHGlobal(InteropTools.SizeOfGuid);
                        Marshal.StructureToPtr(guid, guidPtr, false);
                        enumOptions._pGuid = guidPtr;
                    }
                    hResult = Win32Methods.MappingGetServices(ref enumOptions, ref pService, ref dwServiceCount);
                }
                else
                {
                    hResult = Win32Methods.MappingGetServices(IntPtr.Zero, ref pService, ref dwServiceCount);
                }
                if (hResult != 0)
                {
                    throw new LinguisticException(hResult);
                }
                if ((pService == IntPtr.Zero) != (dwServiceCount == 0))
                {
                    throw new InvalidOperationException();
                }
                IntPtr[] services = new IntPtr[dwServiceCount];
                ServiceCache.Instance.RegisterServices(ref pService, services);
                MappingService[] result = new MappingService[dwServiceCount];
                for (int i = 0; i < dwServiceCount; ++i)
                {
                    result[i] = new MappingService(services[i]);
                }
                return(result);
            }
            finally
            {
                if (pService != IntPtr.Zero)
                {
                    // Ignore the result if an exception is being thrown.
                    Win32Methods.MappingFreeServices(pService);
                }
                if (guidPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(guidPtr);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a new <see cref="MappingService">MappingService</see> object by instanciating an ELS service
        /// by its guid. For Windows 7, the only supported GUIDs are provided as
        /// readonly members of the <see cref="MappingAvailableServices">MappingAvailableServices</see> class.
        ///
        /// If the service
        /// with the specified guid doesn't exist, a <see cref="LinguisticException">LinguisticException</see> is thrown.
        /// </summary>
        /// <param name="serviceIdentifier">The guid of the service to instantiate.</param>        
        public MappingService(Guid serviceIdentifier)
        {
            ThrowIfNotWin7();

            IntPtr servicePointer;
            UInt32 serviceCount = 0;
            UInt32 hresult = 0;

            // First, check to see if we already have the service in the cache:
            servicePointer = ServiceCache.Instance.GetCachedService(ref serviceIdentifier);
            if (servicePointer != IntPtr.Zero)
            {
                _service = servicePointer;
                _win32Service = InteropTools.Unpack<Win32Service>(_service);
            }
            else // pService is IntPtr.Zero in this case.
            {
                // If we don't, we must find it via MappingGetServices:
                IntPtr guidPtr = IntPtr.Zero;
                try
                {
                    guidPtr = Marshal.AllocHGlobal(InteropTools.SizeOfGuid);
                    Win32EnumOptions enumOptions = new Win32EnumOptions();
                    enumOptions._size = InteropTools.SizeOfWin32EnumOptions;
                    Marshal.StructureToPtr(serviceIdentifier, guidPtr, false);
                    enumOptions._pGuid = guidPtr;
                    hresult = Win32NativeMethods.MappingGetServices(ref enumOptions, ref servicePointer, ref serviceCount);
                    if (hresult != 0)
                    {
                        throw new LinguisticException(hresult);
                    }
                    if (servicePointer == IntPtr.Zero)
                    {
                        throw new InvalidOperationException();
                    }
                    if (serviceCount != 1)
                    {
                        hresult = Win32NativeMethods.MappingFreeServices(servicePointer);
                        if (hresult == 0)
                        {
                            throw new InvalidOperationException();
                        }
                        else
                        {
                            throw new LinguisticException(hresult);
                        }
                    }
                    IntPtr[] services = new IntPtr[1];
                    ServiceCache.Instance.RegisterServices(ref servicePointer, services);
                    _service = services[0];
                    _win32Service = InteropTools.Unpack<Win32Service>(_service);
                }
                finally
                {
                    if (servicePointer != IntPtr.Zero)
                    {
                        // Ignore the result if an exception is being thrown.
                        Win32NativeMethods.MappingFreeServicesVoid(servicePointer);
                    }
                    if (guidPtr != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(guidPtr);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public MappingService(Guid serviceGuid)
        {
            // Throw PlatformNotSupportedException if not running on Win7 or greater
            ThrowIfNotWin7();

            IntPtr pService;
            UInt32 dwServiceCount = 0;
            UInt32 hResult = 0;

            // First, check to see if we already have the service in the cache:
            pService = ServiceCache.Instance.GetCachedService(ref serviceGuid);
            if (pService != IntPtr.Zero)
            {
                _service = pService;
                InteropTools.Unpack(out _win32Service, _service);
            }
            else // pService is IntPtr.Zero in this case.
            {
                // If we don't, we must find it via MappingGetServices:
                IntPtr guidPtr = IntPtr.Zero;
                try
                {
                    guidPtr = Marshal.AllocHGlobal(InteropTools.SizeOfGuid);
                    Win32EnumOptions enumOptions = new Win32EnumOptions();
                    enumOptions._size = InteropTools.SizeOfWin32EnumOptions;
                    Marshal.StructureToPtr(serviceGuid, guidPtr, false);
                    enumOptions._pGuid = guidPtr;
                    hResult = Win32Methods.MappingGetServices(ref enumOptions, ref pService, ref dwServiceCount);
                    if (hResult != 0)
                    {
                        throw new LinguisticException(hResult);
                    }
                    if (pService == IntPtr.Zero)
                    {
                        throw new InvalidOperationException();
                    }
                    if (dwServiceCount != 1)
                    {
                        hResult = Win32Methods.MappingFreeServices(pService);
                        if (hResult == 0)
                        {
                            throw new InvalidOperationException();
                        }
                        else
                        {
                            throw new LinguisticException(hResult);
                        }
                    }
                    IntPtr[] services = new IntPtr[1];
                    ServiceCache.Instance.RegisterServices(ref pService, services);
                    _service = services[0];
                    InteropTools.Unpack(out _win32Service, _service);
                }
                finally
                {
                    if (pService != IntPtr.Zero)
                    {
                        // Ignore the result if an exception is being thrown.
                        Win32Methods.MappingFreeServices(pService);
                    }
                    if (guidPtr != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(guidPtr);
                    }
                }
            }
        }
 internal static extern uint MappingGetServices(ref Win32EnumOptions enumOptions, ref IntPtr services, ref uint servicesCount);
Exemplo n.º 6
0
        /// <summary>
        /// Constructs a new <see cref="MappingService">MappingService</see> object by instanciating an ELS service
        /// by its guid. For Windows 7, the only supported GUIDs are provided as
        /// readonly members of the <see cref="MappingAvailableServices">MappingAvailableServices</see> class.
        ///
        /// If the service
        /// with the specified guid doesn't exist, a <see cref="LinguisticException">LinguisticException</see> is thrown.
        /// </summary>
        /// <param name="serviceIdentifier">The guid of the service to instantiate.</param>
        public MappingService(Guid serviceIdentifier)
        {
            ThrowIfNotWin7();

            IntPtr servicePointer;
            UInt32 serviceCount = 0;
            UInt32 hresult      = 0;

            // First, check to see if we already have the service in the cache:
            servicePointer = ServiceCache.Instance.GetCachedService(ref serviceIdentifier);
            if (servicePointer != IntPtr.Zero)
            {
                _service      = servicePointer;
                _win32Service = InteropTools.Unpack <Win32Service>(_service);
            }
            else // pService is IntPtr.Zero in this case.
            {
                // If we don't, we must find it via MappingGetServices:
                IntPtr guidPtr = IntPtr.Zero;
                try
                {
                    guidPtr = Marshal.AllocHGlobal(InteropTools.SizeOfGuid);
                    Win32EnumOptions enumOptions = new Win32EnumOptions();
                    enumOptions._size = InteropTools.SizeOfWin32EnumOptions;
                    Marshal.StructureToPtr(serviceIdentifier, guidPtr, false);
                    enumOptions._pGuid = guidPtr;
                    hresult            = Win32NativeMethods.MappingGetServices(ref enumOptions, ref servicePointer, ref serviceCount);
                    if (hresult != 0)
                    {
                        throw new LinguisticException(hresult);
                    }
                    if (servicePointer == IntPtr.Zero)
                    {
                        throw new InvalidOperationException();
                    }
                    if (serviceCount != 1)
                    {
                        hresult = Win32NativeMethods.MappingFreeServices(servicePointer);
                        if (hresult == 0)
                        {
                            throw new InvalidOperationException();
                        }
                        else
                        {
                            throw new LinguisticException(hresult);
                        }
                    }
                    IntPtr[] services = new IntPtr[1];
                    ServiceCache.Instance.RegisterServices(ref servicePointer, services);
                    _service      = services[0];
                    _win32Service = InteropTools.Unpack <Win32Service>(_service);
                }
                finally
                {
                    if (servicePointer != IntPtr.Zero)
                    {
                        // Ignore the result if an exception is being thrown.
                        Win32NativeMethods.MappingFreeServicesVoid(servicePointer);
                    }
                    if (guidPtr != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(guidPtr);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public MappingService(Guid serviceGuid)
        {
            // Throw PlatformNotSupportedException if not running on Win7 or greater
            ThrowIfNotWin7();

            IntPtr pService;
            UInt32 dwServiceCount = 0;
            UInt32 hResult        = 0;

            // First, check to see if we already have the service in the cache:
            pService = ServiceCache.Instance.GetCachedService(ref serviceGuid);
            if (pService != IntPtr.Zero)
            {
                _service = pService;
                InteropTools.Unpack(out _win32Service, _service);
            }
            else // pService is IntPtr.Zero in this case.
            {
                // If we don't, we must find it via MappingGetServices:
                IntPtr guidPtr = IntPtr.Zero;
                try
                {
                    guidPtr = Marshal.AllocHGlobal(InteropTools.SizeOfGuid);
                    Win32EnumOptions enumOptions = new Win32EnumOptions();
                    enumOptions._size = InteropTools.SizeOfWin32EnumOptions;
                    Marshal.StructureToPtr(serviceGuid, guidPtr, false);
                    enumOptions._pGuid = guidPtr;
                    hResult            = Win32Methods.MappingGetServices(ref enumOptions, ref pService, ref dwServiceCount);
                    if (hResult != 0)
                    {
                        throw new LinguisticException(hResult);
                    }
                    if (pService == IntPtr.Zero)
                    {
                        throw new InvalidOperationException();
                    }
                    if (dwServiceCount != 1)
                    {
                        hResult = Win32Methods.MappingFreeServices(pService);
                        if (hResult == 0)
                        {
                            throw new InvalidOperationException();
                        }
                        else
                        {
                            throw new LinguisticException(hResult);
                        }
                    }
                    IntPtr[] services = new IntPtr[1];
                    ServiceCache.Instance.RegisterServices(ref pService, services);
                    _service = services[0];
                    InteropTools.Unpack(out _win32Service, _service);
                }
                finally
                {
                    if (pService != IntPtr.Zero)
                    {
                        // Ignore the result if an exception is being thrown.
                        Win32Methods.MappingFreeServices(pService);
                    }
                    if (guidPtr != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(guidPtr);
                    }
                }
            }
        }
Exemplo n.º 8
0
 internal static extern uint MappingGetServices(ref Win32EnumOptions enumOptions, ref IntPtr services, ref uint servicesCount);