.NET Components for Mobility

connect to active sync via bluetooth programatically

Last post 04-01-2010 2:57 PM by alanjmcf. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 09-25-2009 2:03 PM

    connect to active sync via bluetooth programatically

    Hi all,

    I am trying to connect to my bluetooth enabled pc from my palm treo in vb.net cf.  The following code is all ive been able to find for example coding.  The problem is that I can connect to my pc, but after it connects, the active sync icons spins for about a minute and then comes up with an error about an unknown device type.  Is there a call or paramter that I am missing to tell active sync what type of device this is or am i missing some form of authentication.

     

    Imports InTheHand.Net.Bluetooth

    Imports InTheHand.Net.Sockets

    Imports InTheHand.Net

    Imports Microsoft.Win32

    Imports Microsoft.VisualBasic

    Module btConnect

    Private Declare Function ActiveSyncStart Lib "aygshell.dll" () as Integer

    Private Declare Function ActiveSyncStop Lib "aygshell.dll" () As Integer

    Sub Main()

    Dim cli As New BluetoothClient

    Dim peers() As BluetoothDeviceInfo = cli.DiscoverDevices

    Dim device As BluetoothDeviceInfo = Nothing

    Dim addr As BluetoothAddress

    Dim intI As Integer

    Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("RMTransfer", True)

    Dim regVal As String = ""

    Dim blnFound As Boolean = False

    Dim intPeer As Integer = 0

    Dim serviceAddress As String = ""

    Dim commonClass As Guid = BluetoothService.SerialPort

    Dim bdi As BluetoothDeviceInfo

    Dim rcdList() As ServiceRecord

    Dim curSvcName As String

    Dim portNumber As Integer

    If (regKey Is Nothing = False) Then

    regVal = regKey.GetValue("Server")

    End If

    Do While (regVal.Length < 1)

    regVal = InputBox("Enter Registry Key Value for the Server".Trim, "Missing Server")

    Loop

    If (regKey Is Nothing = True) Then

    regKey = Registry.LocalMachine.CreateSubKey("RMTransfer")

    End If

    regKey.SetValue("Server", regVal)

    regKey.Close()

    regKey = Nothing

    ' Find the devices

    For intI = 0 To peers.Length - 1

    If (peers(intI).DeviceName = regVal) Then

    device = peers(intI)

    addr = device.DeviceAddress

    blnFound = True

    intPeer = intI

    Exit For

    End If

    Next

    ' If no server, then exit

    If (blnFound = False) Then

    MsgBox("Unable to locate the server.", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Missing Server")

    cli.Dispose()

    cli = Nothing

    Application.Exit()

    End If

    ' Find out if we can locate the active sync service

    addr = device.DeviceAddress

    bdi =
    New BluetoothDeviceInfo(addr)

    rcdList = bdi.GetServiceRecords(commonClass)

    For Each record As ServiceRecord In rcdList

    portNumber = ServiceRecordHelper.GetRfcommChannelNumber(record)

    Try

    curSvcName = record.GetPrimaryMultiLanguageStringAttributeById(0)

    Catch ex As Exception

    Continue For

    End Try

    If (curSvcName.Equals("activesync", StringComparison.InvariantCultureIgnoreCase)) Then

    If (portNumber = -1) Then

    Throw New Exception("Selected Service Not Available")

    End If

    End If

    Exit For

    Next

    If (portNumber = -1) Then

    Throw New Exception("Selected Service Not Available")

    End If

    'portNumber = 3

    Dim port As Byte = CByte(portNumber)Dim rep As New BluetoothEndPoint(addr, BluetoothService.TcpProtocol, port)

    cli.Dispose()

    cli = Nothing

    cli = New BluetoothClient()

    cli.Connect(rep)

    MsgBox(
    "Connected")

    intI = ActiveSyncStart

    Application.Run(
    New frmMain)

    End Sub

    End Module

     

    Thank you in advance for any help.

    Kevin Prince

    Filed under: , , ,
  • 09-25-2009 10:28 PM In reply to

    Re: connect to active sync via bluetooth programatically

    what kind of device are you using to connect with active sync? put some detailed information about the phone.

  • 09-26-2009 12:08 PM In reply to

    Re: connect to active sync via bluetooth programatically

    Hey ya,

     

    the phone is a palm treo pro 850 running windows mobile 6.1.

    If you need any more info, please let me know as this situation is about driving me stupid....

     On the flip side, this is the first time Ive had to post anything to get help and I really do appreciate all the work that you guys do.  Thank you.

     

    Thanks for any help.

     

    Kevin

  • 09-27-2009 2:06 AM In reply to

    Re: connect to active sync via bluetooth programatically

    have you tried reinstelling your AS? and switching to AS 4.5??
  • 09-27-2009 4:45 AM In reply to

    Re: connect to active sync via bluetooth programatically

    You successfully made *your* program connect to the Activesync service, but that's no use.  It needs to be the local ActiveSync program that makes the connection..

    The FAQ at (http://msdn.microsoft.com/en-us/library/aa911758.aspx) suggests maybe calling Process.Start/shellExecuting "Wcesmgr.exe /syncnow" to start the sync.  So manually set the default to Bluetooth first (or maybe see "Cnct" at http://msdn.microsoft.com/en-us/library/aa914986.aspx

  • 09-29-2009 10:22 AM In reply to

    Re: connect to active sync via bluetooth programatically

    Hey there,

    Setting the active sync default  profile to the bluetooth profile now allows it to start when the wce device starts repllog.exe program.  This works good.  A bit of a pain to work out since you need a backwards apostrophe for the connection name.  This required setting up the bluetooth server with a new name and then modifying the registry on the device.

    In the device registry, you must ensure that in the hkcu/comm/rasbook that you have a bluetooth profile prefixed by the backwards apostrophe.  When this is done, you can then goto hkcu/controlpanel/comm and then set the cnct value to the bluetooth connection identified above.  This will tell the device to use this profile when activesync connects which is done by starting repllog.exe on the device.  The only problem with this solution is when the device gets all of its updates, you cannot disconnect active sync.  Cant kill it or it hangs the port (i think).  Im thinking you must use sendkeys or something somilar to access the activesync menu to send the disconnect sequence.

     

    Again, Thank you very much for your help.  Your replies got me going in the direction I needed to be sent.

     

    Kevin Prince

  • 10-01-2009 4:07 PM In reply to

    Re: connect to active sync via bluetooth programatically

    Good stuff!
  • 03-29-2010 4:46 PM In reply to

    Re: internet over bluetooth?

     I have a wince 5.0 device called mesada gps:

    http://www.gpspassion.com/forumsen/topic.asp?TOPIC_ID=132977

    it runs just fine and I've installed miopocket on it but I want to write a vb.net app that will pair with my iphone over bluetooth and i can browse the internet on the miopocket using my iphone dataplan, NOT activesync.

    Is this possible with the inthehand.net framework dll?

    Thank you!

    Filed under:
  • 04-01-2010 2:57 PM In reply to

    Re: internet over bluetooth?

    No, you need to find an API to get the operating system to connect to the network service (there's no point using 32feet.NET to make a bluetooth connection to the service, then your app would have to send and receive IP packets!).
Page 1 of 1 (9 items)
Copyright © 2001-2012 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting