Sunday, February 25, 2007

The Bluetooth sources

When I wrote my first article on the Widcomm Bluetooth stack, I promised to publish a .NET CF 2.0 library that would abstract the enumeration features of the Widcomm and Microsoft stacks under a unique API. My life became very busy since then, especially when I got a contract for integrating the new version of a mobile GPS application on the Windows Mobile environment. This has been a very interesting challenge that has put all my knowledge through its paces and made me learn a lot: powering off the device, integrating DirectDraw with screen rotations, popping up the phone when a call comes through and the screen is in DirectDraw mode, handling bizzare GPS behaviors, exotic device keys (think HTC 3300)... The works!

Requests for the Bluetooth code and article have not stopped, though so I decided to post links to the unedited versions of the C++ and C# sources. Before I get to fully comment the code and write a proper article, what you see is what you get. The sources are divided into 3 ZIP files:

Bluetooth.zip - Contains a sample C# WM5 application that enumerates devices and services. Also contains the Primeworks.Bluetooth class library.
msbts.zip - The low-level Microsoft Bluetooth stack wrapper.
wcbts.zip - The low-level Widcomm Bluetooth stack wrapper.

Now, I can take my time and write the full length article. All your comments and suggestions are welcome.

29 comments:

Giorgio said...

You are the man! The community loves you...

THANK YOU!!! :D

Unknown said...

Joao,

You have done a lot of work on this - good work.

I'm an experienced software engineer but I have never worked with C/C++. As a result I'm stumbling around a bit with setting this up.

As a start I opened the Widcomm Stack wrapper project, wcbs, in Visual Studio 2005. To make life easier in terms of paths etc I copied the header, library and DLL files from the WIDCOMM BTW-CE SDK directory.

On compiling I receive an "unresolved external symbol" error as follows. Can you advise what I am doing wrong? The files that I added are all in the base project directory.

Thanks,

Eric

Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: enum CSppServer::SPP_SERVER_RETURN_CODE __cdecl CSppServer::CreateConnection(wchar_t *)" (__imp_?CreateConnection@CSppServer@@QAA?AW4SPP_SERVER_RETURN_CODE@1@PA_W@Z) referenced in function SppServerStart wcbts.obj

João Paulo Figueira said...

You must install the Widcomm SDK for your particular platform. Also, these projects were compiled with eVC4 (free download from Microsoft), not VS 2005.

Jesús said...

Hello Joao, and thank you very much for your work.

I am trying to test your code samples but I haven´t been able to run the Enumerate sample because I obtain an exception because It can´t find the wcbts.dll library in execution time.

I have installed WIDCOMM SDK and I have converted and compiled your projects to Visual Studio 2005, however, I dont know why I obtain that error because I have included in the debug(bin) folder that dll. I´ve tried putting in the system32 folder but it doesn´t run either.

The exception is launchd in the WidcommAPI.WidcommStackPresent()method. I have revised that method and modified using a .lib instead of a .dll (because I only have a lib version of the library) but I have the same result.

Do you know what I am doing wrong?

Thanyou in advance :D
Jesus

Wirlo said...

Hello,

Thanks for this amazing code, its really usefull. I have two small questions:

1- I try to compile both wrappers in VS2005 but i cant. Is it possible? or you do it in eVC4 because VS2005 can create this type of library?

2- When think you can have the final release of the article? :)

thanks a lot.

João Paulo Figueira said...

You should be able to compile the eVC4 project under VS 2005. My advice is to create a new project with the same properties.

Wirlo said...

Hello Joao,

i try to create a new project and i have the same problem like eric post. I not have enought knowledge in compilation options and i dont know what to do. I read an article with a problem similar but the compilation options are distinc.

Article ->http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c6867/

Solution to compile in VS->http://www.codeguru.com/cpp/cpp/cpp_managed/interop/comments.php/c6867/?thread=10025

Maybe any can help with this problem

Wirlo said...

Sorry link not post correctly

Article:
http://www.codeguru.com/Cpp/
Cpp/cpp_managed/interop/
article.php/c6867/

Solution to compile in VS:
http://www.codeguru.com/cpp/
cpp/cpp_managed/interop/
comments.php/c6867/?thread=10025

rbergo said...

Hello

I got a look to widcomm wrapper... it seems a good work.
I need to reset the bluetooth radio.
Is it possible or does it will be possible to switch off-on the bluetoot radio?

Thank you
Roberto

Anonymous said...


Eric said...
Joao,

On compiling I receive an "unresolved external symbol" error as follows. Can you advise what I am doing wrong? The files that I added are all in the base project directory.

----------

Hello, did you checked the wchar_t consistency?

see
http://nativespeech.blogspot.com/2007/06/inconsistent-wchart-representation.html

regards

- z

aana said...

A lot of bluetooth sources are there. Infact a great blog on revolutionising wireless technology- Bluetooth. Those were of a great help.
Thanks!!

Unknown said...

Hello Joao,

First, I apologize for revising this topic.

I'd like to ask if anyone has played with CL2CapConn::OnCongestionStatus() on WidComm SDK 5.1.0, which vanishes in version 6.1.0? If so, what is your experience with that API? I am currently receiving only one congestion=TRUE notification, but nothing else after that.
Also, CBtIf::SwitchRole() is also gone in 6.1.0? Any work-around?

I'm using VC2005, Widcomm 5.1.0 on XP.

Thank you for any comment.

Unknown said...

João,

This is an incredible piece of work. I was easily able to port and compile your wrappers from eVC4 projects to VS2005, and to compile for both Pocket PC 2003 and WM5.

I was also able to easily compile your C# library and run your sample.

I just want to say - you've saved me a ton of work. This is absolutely incredible - thank you!

I did have a question - there's some interest in having this work incorporated into the 32Feet.Net Compact Framework Bluetooth library. Would you be interested in allowing your work to be so incorporated?

João Paulo Figueira said...

I would be delighted to add this code to 32feet, but it is still mising lots of stuff. Time keeps slipping through my fingers like sand and this code is shamefully (for me) abandoned... So please take it and do whatever you need to do with it!

Unknown said...

João,

That's great to hear - It's something I'd love to work on in my spare time (not that there's much of it, but.. I need interesting projects to keep me sane).

I'll keep you updated!

Yusuf Bekar Mağduru said...
This comment has been removed by the author.
Yusuf Bekar Mağduru said...

Thanks for all ;)

I want see rssi value. How i see it ?

rano said...

Hi,
I will programm a bluetooth communication with the microcontroller (with bleutoth module)and a PDA.
is this DLL for free use. how can I use it. what is primworks DLL? is it free for use too?

its my first application with bluetooth and Framework. (VS 2005) windows Mobile 6
Thanks

Célio said...

Olá João,
Pelo que entendi esse código localiza todas as conexões ativas de bluetooth não ?
Pos bem, eu compilei o código com o VS 2005 e instalei no pocket-pc da Hp IPAQ hw6945 e ao selecionar a opção "Enumerate Devices", liguei o bluetooth do meu celular ("telemovel" ) para verificar se o programa o localizaria mas isso não aconteceu.

Tú tens alguma idéia do ocorrido ?

Abraços.

rano said...

I hav the some Problem As jesus but with other line MicrosoftAPI.CreateStack:
namespace Primeworks.Bluetooth.Microsoft
{......
m_pStack = MicrosoftAPI.CreateStack();
.......

this is rhe error:
Der Einstiegspunkt 'CreateStack' in der PInvoke-DLL 'msbts.dll' wurde nicht gefunden.

'CreateStack' in PInvoke-DLL msbts.dll not found!!!!!!

João Paulo Figueira said...

I would be delighted to add this code to 32feet, but it is still mising lots of stuff. Time keeps slipping through my fingers like sand and this code is shamefully (for me) abandoned... So please take it and do whatever you need to do with it!

João Paulo Figueira said...

Make sure the msbts.dll is on the DLL search path.

rano said...

Thanks for the Answer. Itry to build the msbts with VS2005 I receive linker extern errors:

Fehler 8 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "WSALookupServiceEnd" in Funktion ""protected: unsigned long __cdecl CMicrosoftStack::DiscoverServices(unsigned __int64,struct _GUID *)" (?DiscoverServices@CMicrosoftStack@@IAAK_KPAU_GUID@@@Z)". MicrosoftStack.obj

Fehler 9 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "WSALookupServiceNextW" in Funktion ""protected: unsigned long __cdecl CMicrosoftStack::DiscoverServices(unsigned __int64,struct _GUID *)" (?DiscoverServices@CMicrosoftStack@@IAAK_KPAU_GUID@@@Z)". MicrosoftStack.obj

Fehler 10 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "WSAGetLastError" in Funktion ""protected: unsigned long __cdecl CMicrosoftStack::DiscoverServices(unsigned __int64,struct _GUID *)" (?DiscoverServices@CMicrosoftStack@@IAAK_KPAU_GUID@@@Z)". MicrosoftStack.obj

Fehler 11 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "WSALookupServiceBeginW" in Funktion ""protected: unsigned long __cdecl CMicrosoftStack::DiscoverServices(unsigned __int64,struct _GUID *)" (?DiscoverServices@CMicrosoftStack@@IAAK_KPAU_GUID@@@Z)". MicrosoftStack.obj

Fehler 12 error LNK2001: Nicht aufgelöstes externes Symbol "RFCOMM_PROTOCOL_UUID". NodeData.obj

any Idee. Itested some things from Internet but no result?
Eric how are you solved your Problem.

Eduardo Castro said...

I am getting the following error
Can't find PInvoke DLL 'wcbts.dll' but I have already copied the file the directory where the .exe is stored.

Anonymous said...

Is there a way to get local device address with this wrapper?? If not, how can I do that?

Anonymous said...

buy wow goldAsesor ProfessionalUruguayProfessionalbuy wow goldOfficeLinksNotice

Boris Torrado said...

Hi guys...

I don't know, if is too late for help, but, I had the same error Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: enum CSppServer::SPP_SERVER_RETURN_CODE __cdecl CSppServer::CreateConnection(wchar_t *)" (__imp_?CreateConnection@CSppServer@@QAA?AW4SPP_SERVER_RETURN_CODE@1@PA_W@Z) referenced in function SppServerStart wcbts.obj

And I solved the problem including in The Properties Project, Configuration Properties, Linker, Input, in the Additional Dependencies: Bthguid.lib

then I get compiled the Joao's Dll.
hope was helpful...

Anonymous said...

http://clipboarded.blogspot.com/2007/10/vim-as-ide.html

Anonymous said...

Your blog is wonderful, I like it very much, thank you!
By the way, do you like polo shirts, which are very chic, especially the polo t shirts, I love them very much. I also like playing tennis rackets, it can keep healthy, what do you like to do?
We are the outlet of polo t shirts women, polo t shirts on sale, polo t shirts for women, polo shirts on sale, these products are best-seller in our store online.besides we also sell polo shirts men, men's polo shirt, men polo shirt, mens polo shirts, mens polo shirt and cheap polo shirts, discount polo shirts, men's polo shirts, women's polo shirts We are also the outlet of cheap tennis racket, discount tennis racket, and the main product is prince tennis racquet, head tennis rackets, wilson tennis racket, babolat tennis racquet.You are warmly welcomed to my store online!