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

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


EwSAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mikal613Commented:
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
Mikal613Commented:
try this

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

Uninstall ActiveSync 3.7 Startover and follow those directions on the Link.
Mikal613Commented:
Give attention to Step 5

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

OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Mikal613Commented:
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
Mikal613Commented:
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.
EwSAuthor Commented:
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!
jason_cartwrightCommented:
I'm having this same issue. Can you post the modified code that solved the issue?
EwSAuthor Commented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jason_cartwrightCommented:
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.
zippy6000Commented:
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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.