Ejemplo n.º 1
0
        public void SetDefaultEndPoint(string deviceId, EDataFlow flow, IEnumerable <ERole> roles, uint processId)
        {
            Trace.WriteLine($"ExtendedPolicyClient SetDefaultEndPoint {deviceId} [{flow}] {processId}");
            try
            {
                if (string.IsNullOrEmpty(deviceId))
                {
                    return;
                }

                using var deviceIdStr = HSTRING.FromString(GenerateDeviceId(deviceId, flow));
                foreach (var eRole in roles)
                {
                    PolicyConfig.SetPersistedDefaultAudioEndpoint(processId, flow, eRole, deviceIdStr);
                }
            }
            catch (COMException e) when((e.ErrorCode & ErrorConst.COM_ERROR_MASK) == ErrorConst.COM_ERROR_NOT_FOUND)
            {
                throw new DeviceNotFoundException($"Can't set default as {deviceId}", e, deviceId);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"{ex}");
            }
        }
Ejemplo n.º 2
0
        static IXmlNodeList GetNodes(IXmlDocument xmldoc, string tagName)
        {
            IXmlNodeList nodes;

            using (var hStrign_tagName = HSTRING.FromString(tagName))
                ComFunctions.CheckHRESULT(xmldoc.GetElementsByTagName(hStrign_tagName, out nodes));
            return(nodes);
        }
Ejemplo n.º 3
0
        static IXmlElement CreateElement(IXmlDocument xmldoc, string elementName)
        {
            IXmlElement element;

            using (var hStrign_elementName = HSTRING.FromString(elementName))
                ComFunctions.CheckHRESULT(xmldoc.CreateElement(hStrign_elementName, out element));
            return(element);
        }
Ejemplo n.º 4
0
        static void SetNodeValueString(string str, IXmlDocument xmldoc, IXmlNode node)
        {
            IXmlText textNode;

            using (var hStrign_str = HSTRING.FromString(str))
                ComFunctions.CheckHRESULT(xmldoc.CreateTextNode(hStrign_str, out textNode));
            AppendNode(node, (IXmlNode)textNode);
        }
        public static IAudioPolicyConfigFactory Create()
        {
            var iid = GuidGenerator.CreateIID(typeof(IAudioPolicyConfigFactory));

            using var name = HSTRING.FromString("Windows.Media.Internal.AudioPolicyConfig");
            ComBase.RoGetActivationFactory(name, ref iid, out object factory);
            return(factory.As <IAudioPolicyConfigFactory>());
        }
 public static unsafe void StringToHStringReference(
 char* pchPinnedSourceString,
 string sourceString,
 HSTRING_HEADER* pHeader,
 HSTRING* phString)
 {
     throw new PlatformNotSupportedException("StringToHStringReference");
 }
Ejemplo n.º 7
0
    /// <include file='WinRT.xml' path='doc/member[@name="WinRT.OriginateError"]/*' />
    public static BOOL OriginateError(HRESULT error, HSTRING message)
    {
        if ((((HRESULT)(error)) >= 0))
        {
            return(0);
        }

        return(RoOriginateError(error, message));
    }
Ejemplo n.º 8
0
    /// <include file='WinRT.xml' path='doc/member[@name="WinRT.TransformError"]/*' />
    public static BOOL TransformError(HRESULT oldError, HRESULT newError, HSTRING message)
    {
        if ((oldError == newError) || ((((HRESULT)(oldError)) >= 0) && (((HRESULT)(newError)) >= 0)))
        {
            return(0);
        }

        return(RoTransformError(oldError, newError, message));
    }
Ejemplo n.º 9
0
        static void SetImageSrc(IXmlDocument xmldoc, string imagePath)
        {
            IXmlNode imageNode = GetNode(xmldoc, "image");
            IXmlNode srcAttribute;

            using (var hString_name = HSTRING.FromString("src"))
                ComFunctions.CheckHRESULT(imageNode.Attributes.GetNamedItem(hString_name, out srcAttribute));
            SetNodeValueString(imagePath, xmldoc, srcAttribute);
        }
Ejemplo n.º 10
0
            string GetActivationString(IToastActivatedEventArgs args)
            {
                HSTRING activationString = new HSTRING();

                if (args != null)
                {
                    args.GetArguments(out activationString);
                }
                return(activationString.GetString());
            }
Ejemplo n.º 11
0
 public static string MarshalIntoString(this HSTRING hStr)
 {
     unsafe
     {
         uint   length  = 0;
         PCWSTR pBuffer = WindowsGetStringRawBuffer(hStr, &length);
         string str     = new((char *)pBuffer, 0, (int)length);
         WindowsDeleteString(hStr);
         return(str);
     }
 }
Ejemplo n.º 12
0
        public static unsafe string HStringToString(HSTRING pHString)
        {
            if (pHString.handle == IntPtr.Zero)
            {
                return String.Empty;
            }

            uint length = 0;
            char* pchBuffer = ExternalInterop.WindowsGetStringRawBuffer(pHString.handle.ToPointer(), &length);

            return new string(pchBuffer, 0, (int)length);
        }
Ejemplo n.º 13
0
        public static unsafe void StringToHStringReference(
            char* pchPinnedSourceString,
            string sourceString,
            HSTRING_HEADER* pHeader,
            HSTRING* phString)
        {
            if (sourceString == null)
                throw new ArgumentNullException("sourceString", SR.Null_HString);

            int hr = ExternalInterop.WindowsCreateStringReference(
                pchPinnedSourceString,
                (uint)sourceString.Length,
                pHeader,
                (void**)phString);

            if (hr < 0)
                throw Marshal.GetExceptionForHR(hr);
        }
Ejemplo n.º 14
0
        public string GetDesktopName(object desktop)
        {
            IComVirtualDesktop comDesktop = (IComVirtualDesktop)desktop;
            // get desktop name
            string?desktopName = null;

            try
            {
                desktopName = new HSTRING(comDesktop.GetName()).MarshalIntoString();
            }
            catch { }

            // no name found, generate generic name
            if (string.IsNullOrEmpty(desktopName))
            { // create name "Desktop n" (n = number starting with 1)
                desktopName = "Desktop " + (GetDesktopIndex(IntPtr.Zero, comDesktop) + 1).ToString();
            }
            return(desktopName);
        }
Ejemplo n.º 15
0
    public static HRESULT ActivateInstance <T>(HSTRING activatableClassId, T **instance)
        where T : unmanaged
    {
        *instance = null;

        IInspectable *pInspectable;
        HRESULT       hr = RoActivateInstance(activatableClassId, &pInspectable);

        if (SUCCEEDED(hr))
        {
            if (__uuidof <T>() == IID_IInspectable)
            {
                *instance = (T *)pInspectable;
            }
            else
            {
                hr = pInspectable->QueryInterface(__uuidof <T>(), (void **)instance);
                _  = pInspectable->Release();
            }
        }

        return(hr);
    }
Ejemplo n.º 16
0
 public HRESULT put_NextCorrelationVectorForThread(HSTRING cv)
 {
     return(((delegate * unmanaged <ICorrelationVectorInformation *, HSTRING, int>)(lpVtbl[8]))((ICorrelationVectorInformation *)Unsafe.AsPointer(ref this), cv));
 }
Ejemplo n.º 17
0
 static void SetAttribute(IXmlElement node, string attributeName, string attributeValue)
 {
     using (var hString_attributeName = HSTRING.FromString(attributeName))
         using (var hString_attributeValue = HSTRING.FromString(attributeValue))
             ComFunctions.CheckHRESULT(node.SetAttribute(hString_attributeName, hString_attributeValue));
 }
Ejemplo n.º 18
0
 internal static extern int RoOriginateLanguageException(int hr, HSTRING message, IntPtr pLanguageException);
Ejemplo n.º 19
0
 public static extern uint WindowsGetStringLen(HSTRING @string);
Ejemplo n.º 20
0
 public HRESULT RequestAccessForWindowAsync(HWND appWindow, HSTRING sourceIdentity, HSTRING targetIdentity, [NativeTypeName("const IID &")] Guid *riid, void **asyncOperation)
 {
     return(((delegate * unmanaged <IProtectionPolicyManagerInterop *, HWND, HSTRING, HSTRING, Guid *, void **, int>)(lpVtbl[6]))((IProtectionPolicyManagerInterop *)Unsafe.AsPointer(ref this), appWindow, sourceIdentity, targetIdentity, riid, asyncOperation));
 }
Ejemplo n.º 21
0
        static int GetIndexedProperty__STUB(
                    System.IntPtr pComThis,
                    HSTRING unsafe_name,
                    TypeName unsafe_type,
                    IntPtr __IntPtr__unsafe_customProperty)
        {
            //__com_Windows_UI_Xaml_Data__ICustomProperty** unsafe_customProperty = (__com_Windows_UI_Xaml_Data__ICustomProperty**)__IntPtr__unsafe_customProperty;
            void** unsafe_customProperty = (void**)__IntPtr__unsafe_customProperty;

            try
            {
                object target = ComCallableObject.FromThisPointer(pComThis).TargetObject;
                string propertyName = McgMarshal.HStringToString(unsafe_name);
                Type indexerType = McgMarshal.TypeNameToType(unsafe_type.Name, (int)unsafe_type.Kind);

                ICustomProperty property = ManagedGetIndexedProperty(target, propertyName, indexerType);
                *unsafe_customProperty = (void*)McgComHelpers.ManagedObjectToComInterface(
                    property,
                    typeof(ICustomProperty).TypeHandle);
            }
            catch (Exception ex)
            {
                return McgMarshal.GetHRForExceptionWinRT(ex);
            }

            return Interop.COM.S_OK;
        }
Ejemplo n.º 22
0
 public static extern HRESULT WindowsSubstringWithSpecifiedLength(HSTRING @string, [NativeTypeName("UINT32")] uint startIndex, [NativeTypeName("UINT32")] uint length, HSTRING *newString);
 internal static unsafe int StringToHStringNoNullCheck(string sourceString, HSTRING* hstring)
 {
     throw new PlatformNotSupportedException("StringToHStringNoNullCheck");
 }
Ejemplo n.º 24
0
 public static extern HRESULT WindowsDeleteString(HSTRING @string);
Ejemplo n.º 25
0
 public static extern HRESULT WindowsSubstring(HSTRING @string, [NativeTypeName("UINT32")] uint startIndex, HSTRING *newString);
Ejemplo n.º 26
0
 public static extern HRESULT WindowsStringHasEmbeddedNull(HSTRING @string, BOOL *hasEmbedNull);
Ejemplo n.º 27
0
 public static extern BOOL WindowsIsStringEmpty(HSTRING @string);
Ejemplo n.º 28
0
 public static extern ushort *WindowsGetStringRawBuffer(HSTRING @string, [NativeTypeName("UINT32 *")] uint *length);
Ejemplo n.º 29
0
 public HRESULT SetActivitySourceHost(HSTRING activitySourceHost)
 {
     return ((delegate* unmanaged<IUserActivitySourceHostInterop*, HSTRING, int>)(lpVtbl[6]))((IUserActivitySourceHostInterop*)Unsafe.AsPointer(ref this), activitySourceHost);
 }
Ejemplo n.º 30
0
 public static extern HRESULT WindowsConcatString(HSTRING string1, HSTRING string2, HSTRING *newString);
Ejemplo n.º 31
0
 internal static unsafe string HStringToString(IntPtr hString)
 {
     HSTRING hstring = new HSTRING(hString);
     return HStringToString(hstring);
 }
Ejemplo n.º 32
0
 public static extern HRESULT WindowsReplaceString(HSTRING @string, HSTRING stringReplaced, HSTRING stringReplaceWith, HSTRING *newString);
 public static string HStringToString(HSTRING hString)
 {
     throw new PlatformNotSupportedException("HStringToString");
 }
Ejemplo n.º 34
0
 public static extern HRESULT WindowsTrimStringEnd(HSTRING @string, HSTRING trimString, HSTRING *newString);
Ejemplo n.º 35
0
        static int GetCustomProperty__STUB(
                    System.IntPtr pComThis,
                    HSTRING unsafe_name,
                    IntPtr __IntPtr__unsafe_customProperty)
        {

            void** unsafe_customProperty = (void**)__IntPtr__unsafe_customProperty;

            object target = ComCallableObject.FromThisPointer(pComThis).TargetObject;
            string propertyName = McgMarshal.HStringToString(unsafe_name);
            try
            {
                ICustomProperty property = ManagedGetCustomProperty(target, propertyName);
                *unsafe_customProperty = (void*)McgComHelpers.ManagedObjectToComInterface(
                    property,
                    typeof(ICustomProperty).TypeHandle);
            }
            catch (Exception ex)
            {
                return McgMarshal.GetHRForExceptionWinRT(ex);
            }
            return Interop.COM.S_OK;
        }
Ejemplo n.º 36
0
 public static extern int RoOriginateError(int hr, HSTRING hstring);
Ejemplo n.º 37
0
 public static extern int RoOriginateError(int hr, HSTRING hstring);
Ejemplo n.º 38
0
 static internal extern int RoOriginateLanguageException(int hr, HSTRING message, IntPtr pLanguageException);
Ejemplo n.º 39
0
 public static extern HRESULT WindowsCompareStringOrdinal(HSTRING string1, HSTRING string2, [NativeTypeName("INT32 *")] int *result);
Ejemplo n.º 40
0
 public static extern HRESULT WindowsDuplicateString(HSTRING @string, HSTRING *newString);