⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rapistartup.cs

📁 winmobile远程API操作代码
💻 CS
字号:
// RapiStartup.cs - Simple thread-free RAPI startup
// with all P/Invoke declarations included.
//
// Code from _Programming the .NET Compact Framework with C#_
// and _Programming the .NET Compact Framework with VB_
// (c) Copyright 2002-2004 Paul Yao and David Durant. 
// All rights reserved.

using System;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace RapiStartup
{
   public class RapiStartup
   {
      const string m_strAppName = "RapiStartup";

      public RapiStartup()
      {
      }
      
      // -------------------------------------------------------
      // RAPI.DLL Definitions
      // -------------------------------------------------------
      public struct RAPIINIT
      {
         public int cbSize;
         public IntPtr heRapiInit;
         public int hrRapiInit;
      };

      [DllImport("rapi.DLL", CharSet=CharSet.Unicode)]
      public static extern int CeRapiInitEx (ref RAPIINIT p);
      [DllImport("rapi.DLL", CharSet=CharSet.Unicode)]
      public static extern int CeRapiUninit ();

      public const uint S_OK = 0;

      // -------------------------------------------------------
      // Main -- Program entry point
      // -------------------------------------------------------
      public static void Main()
      {
         // Allocate structure for call to CeRapiInitEx
         RAPIINIT ri = new RAPIINIT();
         ri.cbSize = Marshal.SizeOf(ri);

         // Call init function
         int hr = CeRapiInitEx(ref ri);

         // Wrap event handle in corresponding .NET object
         ManualResetEvent mrev = new ManualResetEvent(false);
         mrev.Handle = ri.heRapiInit;

         // Wait five seconds, then fail.
         if (mrev.WaitOne(5000, false) && ri.hrRapiInit == S_OK)
         {
            // Connection established.
            MessageBox.Show("Connection Established", m_strAppName);
         }
         else
         {
            // On failure, disconnect from RAPI.
            CeRapiUninit();

            MessageBox.Show("Timeout - No Device", m_strAppName);
            return;
         }

         // If we get here, we have established a RAPI connection

         // ToDo: Put your RAPI calls here...

         // Cleanup.
         CeRapiUninit();
      }

   } // class RapiStartup
} // namespace RapiStartup

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -