?
Solved

Win32 Bluetooth chat kind of code needed.

Posted on 2009-02-24
8
Medium Priority
?
945 Views
Last Modified: 2013-12-14
Hi ,

I am new to win32 programming and I need to build a bluetooth file transfer (not unsing OBEX) application. I appreciate if some one send my a sample bluetooth code in VC++.

Thanks
0
Comment
Question by:JPGaur
  • 5
  • 3
8 Comments
 
LVL 3

Accepted Solution

by:
btframework earned 500 total points
ID: 23719471
First at all you should know that each bluetooth drivers have its own API. Take a look at thi product: http://www.btframework.com
0
 

Author Comment

by:JPGaur
ID: 23719709
Thanks btframework,

The WCL library can be good, but I need to do all the development using microsoft stack and SDK.
0
 
LVL 3

Assisted Solution

by:btframework
btframework earned 500 total points
ID: 23719929
Aha. Than it is easy :) Take a look on this blog: http://www.lenholgate.com/archives/000102.html it is exlained there very well.
0
What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

 

Author Comment

by:JPGaur
ID: 23720031
Thanks btframework,

This code does not working on desktop, any way I need some code in win32 sdk (not MFC CSocket) for windows mobile device/smartphone.
0
 
LVL 3

Assisted Solution

by:btframework
btframework earned 500 total points
ID: 23720078
MS Bluetooth SDK for WinMobile IS BASED on WindowsSocket. There is no other common API. The code provided on that page will work on WinMobile without changes. If you want more detailed explaination (there are lots of thing you should to know and it is very hard to explaing it here) you may contact me directly by MSN(mike@btframework.com) or ICQ(371012020).

Here is peace of code for discovering BT devices on WinMobile (the code is from working PPC app (www.bluexpand.com)).
DWORD dwDevBufSize = 1024 * 30;
	LPWSAQUERYSET lpResults = (LPWSAQUERYSET)LocalAlloc(LPTR, dwDevBufSize);
	if (lpResults)
	{
		DWORD dwFlags = LUP_CONTAINERS;
		WSAQUERYSET QuerySet;
		ZeroMemory(&QuerySet, sizeof(WSAQUERYSET));
		QuerySet.dwSize = sizeof(WSAQUERYSET);
		QuerySet.dwNameSpace = NS_BTH;
		HANDLE hLookup = NULL;
		
		DWORD dwRes = WSALookupServiceBegin(&QuerySet, dwFlags, &hLookup);
		if (!dwRes)
		{
			dwFlags = LUP_RETURN_NAME | LUP_RETURN_ADDR;
			while ((!dwRes) && m_hWnd)
			{
				DWORD dwResultsSize = dwDevBufSize;
				ZeroMemory(lpResults, dwResultsSize);
 
				dwRes = WSALookupServiceNext(hLookup, dwFlags, &dwResultsSize, lpResults);
				if (!dwRes)
				{
					LPCSADDR_INFO lpCSAddr = (LPCSADDR_INFO)lpResults->lpcsaBuffer;
					if (lpCSAddr)
					{
						PSOCKADDR_BTH lpSockAddrBth =
							(PSOCKADDR_BTH)lpCSAddr->RemoteAddr.lpSockaddr;
						if (lpSockAddrBth)
						{
							CString sServName = L"";
							/*if (BtSettings.m_bCheckForModel)
							{
								DWORD dwServBufSize = 1024 * 30;
								LPWSAQUERYSET lpServResults = (LPWSAQUERYSET)LocalAlloc(LPTR,
									dwServBufSize);
								if (lpServResults)
								{
									GUID Service = L2CAP_PROTOCOL_UUID;
									WSAQUERYSET ServicesQuerySet;
									ZeroMemory(&ServicesQuerySet, sizeof(WSAQUERYSET));
									ServicesQuerySet.dwSize = sizeof(WSAQUERYSET);
									ServicesQuerySet.dwNameSpace = NS_BTH;
									ServicesQuerySet.lpServiceClassId = &Service;
									ServicesQuerySet.lpcsaBuffer = lpResults->lpcsaBuffer;
									HANDLE hServLookup = NULL;
									
									DWORD dwServRes = WSALookupServiceBegin(&ServicesQuerySet,
										0, &hServLookup);
									if (!dwServRes)
									{
										while ((!dwRes) && m_hWnd)
										{
											DWORD dwServResultsSize = dwServBufSize;
											ZeroMemory(lpServResults, dwServResultsSize);
											dwServRes = WSALookupServiceNext(hServLookup, 0,
												&dwServResultsSize, lpServResults);
											if (!dwRes)
											{
												// Decode here
											}
										}
										
										WSALookupServiceEnd(hServLookup);
									}
								}
							}*/
							
							CBtDevice* pDevice = new CBtDevice(lpSockAddrBth->btAddr,
								lpResults->lpszServiceInstanceName, sServName);
							pDevices->Add(pDevice);
						}
					}
				}
			}
			
			WSALookupServiceEnd(hLookup);
		}
		
		LocalFree((HLOCAL)lpResults);
	}

Open in new window

0
 
LVL 3

Assisted Solution

by:btframework
btframework earned 500 total points
ID: 23720104
This code connects t remote device (i do repeat, the code is from working app and has some things which are not related to BT, but I think you can understand it :) )
SOCKADDR_BTH SockAddr;
	DWORD dwSockAddrSize = sizeof(SOCKADDR_BTH);
	ZeroMemory(&SockAddr, dwSockAddrSize);
	SockAddr.addressFamily = AF_BTH;
	SockAddr.btAddr = m_BtAddr;
	SockAddr.serviceClassId = OBEXObjectPushServiceClass_UUID;
 
	BtManager.Lock();
	if (!StartTimer())
	{
		SendMessage(m_hWnd, WM_BT_SEND_COMPLETE, (WPARAM)resIgnored, 0);
		BtManager.Unlock();
		return;
	}
	if (connect(m_hSocket, (PSOCKADDR)&SockAddr, dwSockAddrSize) == SOCKET_ERROR)
	{
		BtManager.Unlock();
		int iRes = WSAGetLastError();
		if ((iRes == WSAEACCES) || (iRes == WSAEADDRINUSE) || (iRes == WSAETIMEDOUT) ||
			(iRes == WSAEADDRNOTAVAIL))
			SendMessage(m_hWnd, WM_BT_SEND_COMPLETE, (WPARAM)resIgnored, 0);
		else
			// WSAECONNABORTED and others not decoded
			SendMessage(m_hWnd, WM_BT_SEND_COMPLETE, (WPARAM)resRejected, 0);
		return;
	}
	BtManager.Unlock();

Open in new window

0
 

Author Comment

by:JPGaur
ID: 23720226
Thanks again btframework:

But my problem is slightly different I got an example in windows mobile 6 SDK BTChat but it seems to works only with itself (need same application installed on the other device) while I need to make it communicate to other device like symbian S60 etc, I was able to change the service Id in this example and set it to generic spp service ID, then the example application was able to send the message to the other device(symbian) , but It can't able to receive the return message from the other symbian device.

So I am done with device discovery, service discovery, connect to other device (any device like symbian/ a desktop which has bluesolie stack) and send a message to that device.
The problem is the BTChat(\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CPP\win32\Bluetooth\BthChat) application is not able to receive an incoming message from an device other then a winmobile device running same application.
0
 
LVL 3

Assisted Solution

by:btframework
btframework earned 500 total points
ID: 23720290
Of course! Because you MUST connect to specified service whcih device can understand. If you would like to send a file to device then you must use OBEX (FTP/OPP or Nokia specified). There is NO way to send message without known the target service. And, of course, there is NO way to send file to target device without OBEX if there is no app running on target device which can understand your own protocol. As I wrote above there are too many things you should to know before work with bluetooth. Good start point is www.bluetooth.org - read the dcs and specs. Or, as I wrote, contact me directly. I'll try to explaing some things.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe how to setup a Cisco WLC 5508 to work with Apple's Bonjour protocol across VLANs.  I will also discuss using screen mirroring and Airplay on an AppleTV v3.  This article covers the wireless network only and requires m…
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

829 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