コード例 #1
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

            // Set up data to send to DLL
            string strHello = "Round-trip data to device and back";
            int    cbInput  = Marshal.SizeOf(strHello);
            int    cbOutput = 0;
            IntPtr ipInput  = Marshal.StringToHGlobalUni(strHello);
            IntPtr ipOutput = IntPtr.Zero;

            // Call device-side DLL
            CeRapiInvoke(@"\windows\SimpleBlockModeInvoke.dll",
                         "LoopbackInvoke",
                         cbInput,
                         ipInput,
                         ref cbOutput,
                         ref ipOutput,
                         0, 0);

            // Convert return value to a string.
            string strOutput = Marshal.PtrToStringUni(ipOutput, cbOutput);

            // Display resulting string.
            MessageBox.Show(strOutput, "CallDeviceDll");

            // Cleanup.
            CeRapiUninit();
        }
コード例 #2
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();
        }
コード例 #3
0
 public static extern int CeRapiInitEx(ref RAPIINIT p);
コード例 #4
0
ファイル: RAPI.cs プロジェクト: ramilexe/tsdfamilia
		/// <summary>
		/// Connect asynchronously to the remote device with a timeout of 0 seconds
		/// </summary>
		/// <param name="WaitForInit">If true the method blocks until RAPI Initializes or throws an error. If false the contructor does not block and the RAPIConnected event signals successful device connection.</param>
		/// <param name="TimeoutSeconds">Asynchronous connections can be set to timeout after a set number of seconds. Synchronous connection wait infinitely by default (and underlying RAPI design). For asynchronous connections, a timeout value of <b>-1</b> is infinite.</param>
		public void Connect(bool WaitForInit, int TimeoutSeconds)
		{
			int ret = 0;
			m_timeout = TimeoutSeconds;

			if(WaitForInit)
			{
				ret = CeRapiInit();
				if( ret != 0)
				{
					int e = CeRapiGetError();

					Marshal.ThrowExceptionForHR(ret);
				}

				lock(this)
				{
					m_connected = true;
				}

				// throw the connected event
				if(RAPIConnected != null)
				{
					RAPIConnected();
				}

				return;
			}

			// non-blocking init call
			m_ri = new RAPIINIT();

			m_ri.cbSize = Marshal.SizeOf(m_ri);
			m_ri.hrRapiInit = m_InitResult;

			m_hInitEvent = CreateEvent(IntPtr.Zero, 0, 0, "OpenNETCF.RAPI");

			if((uint)m_hInitEvent == uint.MaxValue)
			{
				throw new RAPIException("Failed to Initialize RAPI");
			}

			m_ri.heRapiInit = m_hInitEvent;

			ret = CeRapiInitEx(ref m_ri);
			if(ret != 0)
			{
				Marshal.ThrowExceptionForHR(ret);
			}

			// create a wait thread
			m_initThread = new Thread(new ThreadStart(InitThreadProc));

			// Start thread
			m_initThread.Start();
		}
コード例 #5
0
ファイル: RAPI.cs プロジェクト: ultrashot/wpbackup
        /// <summary>
        /// Connect asynchronously to the remote device with a timeout of 0 seconds
        /// </summary>
        /// <param name="WaitForInit">If true the method blocks until RAPI Initializes or throws an error. If false the contructor does not block and the RAPIConnected event signals successful device connection.</param>
        /// <param name="TimeoutSeconds">Asynchronous connections can be set to timeout after a set number of seconds. Synchronous connection wait infinitely by default (and underlying RAPI design). For asynchronous connections, a timeout value of <b>-1</b> is infinite.</param>
        public void Connect(bool WaitForInit = true, int TimeoutSeconds = 0)
        {
            int ret = 0;
            m_timeout = TimeoutSeconds;

            if (WaitForInit)
            {
                ret = CeRapiInit();
                if (ret != 0)
                {
                    int e = CeRapiGetError();

                    Marshal.ThrowExceptionForHR(ret);
                }

                lock (RapiLock) {
                    m_connected = true;
                }

                // throw the connected event
                if (RAPIConnected != null)
                {
                    RAPIConnected();
                }

                return;
            }

            // non-blocking init call
            m_ri = new RAPIINIT();

            m_ri.cbSize = Marshal.SizeOf(m_ri);

            ret = CeRapiInitEx(ref m_ri);
            if (ret != 0)
            {
                Marshal.ThrowExceptionForHR(ret);
            }

            m_hInitEvent = m_ri.heRapiInit;

            // create a wait thread
            m_initThread = new Thread(new ThreadStart(ConnectThreadProc));

            // Start thread
            m_initThread.Start();
        }