Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
i would like to connect windows application to mobile using bluetooth in csharp
Posted
Updated 1-Apr-15 23:16pm
v2
Comments
Richard MacCutchan 2-Apr-15 5:33am    
You need to use Google to find some tutorials/samples of how to communicate via bluetooth.

1 solution

Get DDL to click here


You can use it from C# like this:

C#
[DllImport("bLADEBluetoothLib.dll",
  EntryPoint = "discoverbluetoothdevices",
  CharSet = CharSet.Unicode,
  SetLastError = true)]
private static extern int DiscoverBluetoothDevices(String deviceList);

[DllImport("Ws2.dll",
  SetLastError = true)]
private extern static Int32 WSAGetLastError();

public static string[] GetDiscoverableDevices()
{
  // prepare a 500 character buffer for the DLL to return
  //  the result in
  String deviceList = new String(' ', 500);

  // get a comma-separated list of
  // discoverable Bluetooth devices
  //
  // the number of devices is returned
  int nbrDevices = DiscoverBluetoothDevices(deviceList);

  if (nbrDevices >= 0)
  {
    return deviceList.ToString().Split(new char[] { ',' });
  }
  else
  {
    // if the DLL encounters an error in one of the WinSock
    //  functions it uses, it returns -1
    //
    // you can then use WSAGetLastError to find the source
    //  of the error
    MessageBox.Show(nbrDevices.ToString() +
            " (reason: " + WSAGetLastError() + ")");
    return new string[0];
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900