static BluetoothRadio() { try { // Make generic parameters for the search NativeMethods2.BluetoothFindRadioParams radio = new NativeMethods2.BluetoothFindRadioParams(); // Make a handle for the radio itself IntPtr phRadio = IntPtr.Zero; // Search for the first radio SafeBluetoothRadioFindHandle findHandle = NativeMethods2.BluetoothFindFirstRadio(radio, ref phRadio); // Was a radio found? // if (findHandle == IntPtr.Zero) //{ // int errorCode = Marshal.GetLastWin32Error(); // switch (errorCode) // { // case 259: // // No more data // return; // default: // throw new Win32Exception(Marshal.GetLastWin32Error()); // } //} // Yes. Close the search // NativeMethods2.BluetoothFindRadioClose(findHandle); findHandle.Close(); // If we have a radio, turn it into an object if (phRadio != IntPtr.Zero) { _current = new BluetoothRadio(phRadio); } } catch (Win32Exception ex) { // Notice: Do not allow exceptions to be thrown in a static constructor. // Instead, raise the DeviceDetectionAttemptFailed event to allow the exception to be handled Devices.OnDeviceDetectionAttemptFailed(new DeviceDetectionException(null, ex)); } }
public static void AddToRecentCategory(JumpTask jumpTask) { Verify.IsNotNull <JumpTask>(jumpTask, "jumpTask"); if (Utilities.IsOSWindows7OrNewer) { IShellLinkW shellLinkW = JumpList.CreateLinkFromJumpTask(jumpTask, false); try { if (shellLinkW != null) { NativeMethods2.SHAddToRecentDocs(shellLinkW); } } finally { Utilities.SafeRelease <IShellLinkW>(ref shellLinkW); } } }
internal BluetoothRadio(IntPtr handle) { Handle = handle; NativeMethods2.BluetoothRadioInfo info = new() { ByteSize = 520 }; // Get information for this radio int errorCode = NativeMethods2.BluetoothGetRadioInfo(Handle, ref info); if (errorCode != 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // Load up information Name = info.Name; Class = (DeviceClass)(info.DeviceClass & 0x1F00); MinorClass = (DeviceClass)(info.DeviceClass & 0xFC); ServiceClass = (ServiceClass)(info.DeviceClass & 0xFFE000); }
/// <summary> /// Add the task at the specified file path to the application's JumpList's recent items. /// </summary> /// <remarks> /// This makes the item eligible for inclusion in the special Recent and Frequent categories. /// </remarks> public static void AddToRecentCategory(JumpTask jumpTask) { Verify.IsNotNull(jumpTask, "jumpTask"); // SHAddToRecentDocs only allows IShellLinks in Windows 7 and later. // Silently fail this if that's not the case. // We don't give feedback on success here, so this is okay. if (Utilities.IsOSWindows7OrNewer) { IShellLinkW shellLink = CreateLinkFromJumpTask(jumpTask, false); try { if (shellLink != null) { NativeMethods2.SHAddToRecentDocs(shellLink); } } finally { Utilities.SafeRelease(ref shellLink); } } }
public void SetIsConnectable(bool value) { NativeMethods2.BluetoothEnableIncomingConnections(_handle, value); }
public bool GetIsConnectable() { return(NativeMethods2.BluetoothIsConnectable(_handle)); }
/// <summary> /// Add the item at the specified file path to the application's JumpList's recent items. /// </summary> /// <remarks> /// This makes the item eligible for inclusion in the special Recent and Frequent categories. /// </remarks> public static void AddToRecentCategory(string itemPath) { Verify.FileExists(itemPath, "itemPath"); itemPath = Path.GetFullPath(itemPath); NativeMethods2.SHAddToRecentDocs(itemPath); }
private void PlaybackProc(object playbackStartedEventWaithandle) { Exception exception = null; IntPtr avrtHandle = IntPtr.Zero; string mmcssType = Latency > 25 ? "Audio" : "Pro Audio"; int taskIndex = 0; try { int bufferSize = _audioClient.BufferSize; int frameSize = _outputFormat.Channels * _outputFormat.BytesPerSample; var buffer = new byte[bufferSize * frameSize]; WaitHandle[] eventWaitHandleArray = { _eventWaitHandle }; _audioClient.Start(); _playbackState = PlaybackState.Playing; avrtHandle = NativeMethods2.AvSetMmThreadCharacteristics(mmcssType, ref taskIndex); if (playbackStartedEventWaithandle is EventWaitHandle) { ((EventWaitHandle)playbackStartedEventWaithandle).Set(); playbackStartedEventWaithandle = null; } bool isAudioClientStopped = false; while (PlaybackState != PlaybackState.Stopped) { //based on the "RenderSharedEventDriven"-Sample: http://msdn.microsoft.com/en-us/library/dd940520(v=vs.85).aspx if (_eventSync) { //3 * latency = see msdn: recommended timeout int eventWaitHandleIndex = WaitHandle.WaitAny(eventWaitHandleArray, 3 * _latency, false); if (eventWaitHandleIndex == WaitHandle.WaitTimeout) { //guarantee that the stopped audio client (in exclusive and eventsync mode) can be //restarted below if (PlaybackState != PlaybackState.Playing && !isAudioClientStopped) { continue; } } } else { //based on the "RenderSharedTimerDriven"-Sample: http://msdn.microsoft.com/en-us/library/dd940521(v=vs.85).aspx Thread.Sleep(_latency / 8 > 0 ? _latency / 8 : 1); } if (PlaybackState == PlaybackState.Playing) { if (isAudioClientStopped) { //restart the audioclient if it is still paused in exclusive mode //belongs to the bugfix described below. http://cscore.codeplex.com/workitem/23 _audioClient.Start(); isAudioClientStopped = false; } int padding; if (_eventSync && _shareMode == AudioClientShareMode.Exclusive) { padding = 0; } else { padding = _audioClient.GetCurrentPadding(); } int framesReadyToFill = bufferSize - padding; //avoid conversion errors /*if (framesReadyToFill > 5 && * !(_source is DmoResampler && * ((DmoResampler) _source).OutputToInput(framesReadyToFill * frameSize) <= 0)) * { * if (!FeedBuffer(_renderClient, buffer, framesReadyToFill, frameSize)) * _playbackState = PlaybackState.Stopped; //TODO: Fire Stopped-event here? * }*/ if (framesReadyToFill <= 5) { continue; } if (!FeedBuffer(_renderClient, buffer, framesReadyToFill, frameSize)) { _playbackState = PlaybackState.Stopped; //source is eof } } else if (PlaybackState == PlaybackState.Paused && _shareMode == AudioClientShareMode.Exclusive && !isAudioClientStopped) { //stop the audioclient on paused if the sharemode is set to exclusive //otherwise there would be a "repetitive" sound. see http://cscore.codeplex.com/workitem/23 _audioClient.Stop(); isAudioClientStopped = true; } } if (avrtHandle != IntPtr.Zero) { NativeMethods2.AvRevertMmThreadCharacteristics(avrtHandle); avrtHandle = IntPtr.Zero; } Thread.Sleep(_latency / 2); _audioClient.Stop(); _audioClient.Reset(); } catch (Exception ex) { exception = ex; } finally { //set the playbackstate to stopped _playbackState = PlaybackState.Stopped; if (avrtHandle != IntPtr.Zero) { NativeMethods2.AvRevertMmThreadCharacteristics(avrtHandle); } //set the eventWaitHandle since the Play() method maybe still waits on it (only possible if there were any errors during the initialization) var eventWaitHandle = playbackStartedEventWaithandle as EventWaitHandle; if (eventWaitHandle != null) { eventWaitHandle.Set(); } RaiseStopped(exception); } }