当前位置: 首页>>代码示例>>C#>>正文


C# GCHandle.ToIntPtr方法代码示例

本文整理汇总了C#中System.Runtime.InteropServices.GCHandle.ToIntPtr方法的典型用法代码示例。如果您正苦于以下问题:C# GCHandle.ToIntPtr方法的具体用法?C# GCHandle.ToIntPtr怎么用?C# GCHandle.ToIntPtr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.InteropServices.GCHandle的用法示例。


在下文中一共展示了GCHandle.ToIntPtr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ServiceMain

        private void ServiceMain(int argc, string[] argv)
        {
            GCHandle = GCHandle.Alloc(this);
            DispatcherHandle = RegisterServiceCtrlHandlerEx(ServiceName, new ServiceHandlerEx(ServiceHandler), GCHandle.ToIntPtr(GCHandle));
            if (DispatcherHandle == IntPtr.Zero || DispatcherHandle == new IntPtr(-1))
            {
                Logger.Log(LogLevel.Error, "Invalid handle received from RegisterServiceCtrlHandlerEx");
                return;
            }
            else
            {
                Logger.Log(LogLevel.Debug, "RegisterServiceCtrlHandlerEx returned handle {0}", DispatcherHandle.ToString());
            }

            Logger.SetLogger(new NtEventLogger(), LogLevel.Info);

            int status = OnControl(() => this.OnStart(argv), ServiceState.StartPending, ServiceState.Running);

            if (status != 0)
            {
                SetServiceStatus(ServiceState.Stopped, win32ExitCode: status);
            }
        }
开发者ID:klightspeed,项目名称:CloudPrintProxy,代码行数:23,代码来源:NativeService.cs

示例2: _GetFreeHeader

      ///
      /// Returns the next header we should write to, or blocks until
      /// one is available. The returned header is done and prepared.
      ///
      void _GetFreeHeader( out GCHandle nextIntPtr,
                           out WAVEHDR nextAsHeader )
      {
         while (true)
         {
            // Clear the wave event before checking "done" to 
            // reduce the race condition between checking and 
            // waiting on the event. (it's manual reset...)
            _playEvent.Reset();

            // Note that the header memory fields will be updated
            // by the wave engine at the same time. Oooh, scary!
            // OK, so we're just checking one bit in an int, it's not
            // really dangerous.

            nextFree = _waveHdr[_nextFreeHeader];
            nextAsHeader = (WAVEHDR)nextFree.Target;
            nextIntPtr = nextIntPtr.ToIntPtr();

            if (nextAsHeader.dwFlags & WHDR_DONE)
            {
               if (nextAsHeader.dwFlags & WHDR_PREPARED)
               {
                  int status = waveOutUnprepareHeader
                     ( _waveOutHandle,
                       nextIntPtr,
                       Marshal.sizeof(typeof(WAVEHDR)) );
                  
                  if (status != MMSYSERR_NOERROR)
                  {
                     // Ugh? Still playing? But WHDR_DONE is set!
                     throw new ApplicationException( 
                        String.Format( "Error '{0}' unpreparing wave header",
                                       status ) 
                        );
                  }
               }

               // Switch buffers. Whee.
               _nextFreeHeader = _nextFreeHeader ^ 0x01;
               return;
            }

            // The next buffer is not done. Wait for it to be done.
            // Note there is a race condition here. :(
            _playEvent.WaitOne( 500, false );

            // Could check here to avoid non-buffer-done type events,
            // but really it doesn't matter.
         }
      }
开发者ID:BackupTheBerlios,项目名称:tamjb,代码行数:55,代码来源:OutStreamWin32.cs


注:本文中的System.Runtime.InteropServices.GCHandle.ToIntPtr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。