public struct RAPIINIT 
    { 
        [FieldOffset(0)] 
        public int cbsize; 
        [FieldOffset(4)] 
        public System.IntPtr heRapiInit; 
        [FieldOffset(8)] 
        public int hrRapiInit; 
    };   [DllImport("rapi.dll", CharSet = CharSet.Unicode)] 
      public static extern uint CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT pRapiInit);  //判斷是否連接到pc機,並馬上返回結果       [DllImport("kernel32.dll", SetLastError = true)] 
      public static extern uint WaitForSingleObject(IntPtr hHandle, int milliseconds); private bool Init() 
      { 
          RAPIINIT ri=new RAPIINIT(); 
          ri.cbsize=Marshal.SizeOf(typeof(RAPIINIT)); 
          uint hInitResult = CeRapiInitEx(ref ri); 
          uint dwWaitResult = WaitForSingleObject(ri.heRapiInit, 2000); 
          if (hInitResult ==0 && ri.hrRapiInit == 0 && dwWaitResult != 2000) 
          { 
              Console.Write(" 连接成功");    //不管我pda是否有連接到pc,都執行到這裏 
                                                                              //看了好多人的說法,但是這裏不理解.
              return true;                //CeRapiInitEx()不是返回連接成功與否嗎? 
          } 
          else 
          { 
              // 连接不成功 
              Console.Write(" 连接不成功"); 
              return false; 
          }       }高手們幫忙啊.這個問題我已經開了幾個貼了,沒人可以幫我解決.
急啊!!

解决方案 »

  1.   

    if (hInitResult ==0 && ri.hrRapiInit == 0 && dwWaitResult != 2000) 
    一直为true ,肯定是判定条件错了
      

  2.   

    LZ我没看到你问题提在哪里
    到底是同步程序看不懂需要解释还是同步程序有问题要大家找BUG?up
    jf
      

  3.   

     if (hInitResult ==0 && ri.hrRapiInit == 0 && dwWaitResult != 2000) 
    這個判斷是否正確,如果正確就代表pda連上電腦了,但是不管我的activesync是否與有與pda同步,都會執行到它,所以我也不知問題在哪?我主要想獲取個條件來判斷是否pda有與電腦同步,有執行一個動作,沒有繼續嘗試連接