Solved

This VB code works with Active Sync 3.5 and 3.6, but not 3.7

Posted on 2003-11-13
12
759 Views
Last Modified: 2013-12-27
I'm using the following VB 6.0 code to connect to my Pocket PC. RapiConnect() is successful with Active Sync 3.5 and 3.6, but not 3.7.1
I would think 3.7 would be backwards compatible, but it looks like rapi.dll has changed... Does anyone why it's not working? Thank you!
Option Explicit

Private Type CEOSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Private Type RAPIINIT
    cbSize As Long
    heRapiInit As Long
    hrRapiInit As Long
End Type

Private Declare Function CeRapiInitEx Lib "rapi.dll" ( _
    pRapiInit As RAPIINIT) As Long

Private Declare Function CeGetVersionEx Lib "rapi.dll" ( _
    lpVersionInformation As CEOSVERSIONINFO) As Boolean
   

Public Function RapiConnect() As Boolean
    ' Initiates a connection and returns True if it connected, False if it did not
   
    Dim pRapiInit As RAPIINIT
   
    On Error GoTo RapiConnect_Err

    With pRapiInit
        .cbSize = Len(pRapiInit)
    End With
    Call CeRapiInitEx(pRapiInit)
    RapiConnect = RapiGetCEOSVersionString <> ""
    Exit Function
   
RapiConnect_Err:
    RapiConnect = False
End Function


Public Function RapiGetCEOSVersionString() As String
    ' Returns the Major, Minor, and Build number of the OS In a string
    Dim ceosver As CEOSVERSIONINFO
   
    ceosver.dwOSVersionInfoSize = Len(ceosver)
   
    If CeGetVersionEx(ceosver) Then
        RapiGetCEOSVersionString = ceosver.dwMajorVersion & "." & _
            ceosver.dwMinorVersion & "." & _
            ceosver.dwBuildNumber & " " & _
            Left$(ceosver.szCSDVersion, _
            InStr(ceosver.szCSDVersion, Chr$(0)) - 1)
    Else
        RapiGetCEOSVersionString = ""
    End If
End Function


0
Comment
Question by:EwS
  • 5
  • 2
  • 2
  • +1
12 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 9742688
Microsft ActiveSync was made for Windows CE 4.2

The only languages that can be used for 4.2 (that are supported) are eMbedded Visual C++ 4.2 and Visual Studio.NET

I would suggest Upgrading your project to One of these 2

http://support.microsoft.com/default.aspx?scid=kb;en-us;307256
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9742723
try this

http://www.aximsite.com/boards/showthread/t-21809.html

Uninstall ActiveSync 3.7 Startover and follow those directions on the Link.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9742728
Give attention to Step 5

5th step
Copy rapi.dll and ceutil.dll from Program Files\Microsoft ActiveSync to Windows\System32

0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9742737
Also

C:\WINDOWS\SYSTEM32\rapi.dll
Old date: 5/28/2002 3:54 PM
New date: 3/26/2003 6:28 PM
Old size: 73,809 bytes
New size: 73,803 bytes
It did change
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9742747
There is a problem with 3.7.1 and until Microsoft fix it you will need to install 3.7 or earlier.
This should still work on almost all devices.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:EwS
ID: 9749184
Thanks for all the help and quick responses!
Actually, it seems that Microsoft introduced changes in the timing with ActiveSync 3.7 and it takes a bit longer to establish a connection with the device. My solution: I used MsgWaitForMultipleObjects function with a timeout value of 5 seconds and it worked!
0
 

Expert Comment

by:jason_cartwright
ID: 10552147
I'm having this same issue. Can you post the modified code that solved the issue?
0
 

Accepted Solution

by:
EwS earned 0 total points
ID: 10552776
Here it is:

Option Explicit

Private Type RAPIINIT
    cbSize As Long
    heRapiInit As Long
    hrRapiInit As Long
End Type

Private Declare Function CeRapiInitEx Lib "rapi.dll" ( _
    pRapiInit As RAPIINIT) As Long

Private Declare Function MsgWaitForMultipleObjects Lib "user32" ( _
    ByVal nCount As Long, _
    ByRef pHandles As Long, _
    ByVal fWaitAll As Long, _
    ByVal dwMilliseconds As Long, _
    ByVal dwWakeMask As Long) As Long
   
' GetQueueStatus flags
Private Const QS_KEY = &H1
Private Const QS_MOUSEMOVE = &H2
Private Const QS_MOUSEBUTTON = &H4
Private Const QS_POSTMESSAGE = &H8
Private Const QS_TIMER = &H10
Private Const QS_PAINT = &H20
Private Const QS_SENDMESSAGE = &H40
Private Const QS_HOTKEY = &H80

Private Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)
Private Const QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or QS_HOTKEY)
Private Const QS_ALLINPUT = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY)

' Possible returns from MsgWaitForMultipleObjects
Private Const WAIT_OBJECT_0 = 0&
Private Const WAIT_TIMEOUT = &H102&
Private Const WAIT_ABANDONED_0 = &H80&
   
Private Const INFINITE = -1&
   

Public Function RapiConnect() As Boolean
    ' Initiates a connection and returns True if it connected, False if it did not
   
    On Error GoTo RapiConnect_Err

    Dim pRapiInit As RAPIINIT
   
    With pRapiInit
        .cbSize = Len(pRapiInit)
    End With
    Call CeRapiInitEx(pRapiInit)
   
    Dim retval As Long
    retval = 1
   
    Do
        ' Try to connect to the device until a connection is established or a timeout (5 seconds) occurs
        retval = MsgWaitForMultipleObjects(1&, pRapiInit.heRapiInit, False, 5000, _
            (QS_POSTMESSAGE Or QS_SENDMESSAGE))
        DoEvents
    Loop Until retval = WAIT_OBJECT_0 Or retval = WAIT_TIMEOUT
   
    If retval = 0 Then
        RapiConnect = True
    Else
        RapiConnect = False
    End If
       
    Exit Function
   
RapiConnect_Err:
    RapiConnect = False

End Function


0
 

Expert Comment

by:jason_cartwright
ID: 10553366
Great, that will be a big help. Also, it seems that the adofltr.dll methods DEVICETODESKTOP and DESKTOPTODEVICE have been affected. Has anyone encountered this with ActiveSync 3.7 and found a resolution?

Looks like it's about time to convert these "legacy" VB apps up to .NET.
0
 

Expert Comment

by:zippy6000
ID: 10861887
I am having the same problem as above.  I have added the example code to my project and still receive an error using ActiveSync 3.7.1  It actually closes VB during the sync so there is no way to debug the code.  Does anyone else have a solution for this problem?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now