在vs中使用widcom bluetooth sdk編譯藍牙程序可能遇到的errs和solutions

原文鏈接 http://windowsmobiledn.com/forum/viewtopic.php?t=7800

 

First off, nice tutorial! Information seems to be quite hard to find on Bluetooth programming, for some particularly odd reason.

I'll post a few comments on my experience with the SDK... feel free to remove this message if you find it to be of no use.

*** WARNING ***
Alright, this is a warning for all developers still just THINKING about developing for the Widcomm/Broadcom Bluetooth Stack using the Widcomm SDK (CE or Desktop) with Visual Studio 2005... it's a pain!

1.1 ENVIRONMENT
_______________
Both SDKs (CE and Desktop) were developed to use with Microsoft Embedded Visual C++ 3.0 and 4.0 (eVC3 and eVC4); this is a free environment provided by Microsoft on the MSDN Web site. Although it is technically possible to work with Visual C++ .NET, as mentioned within the Broadcom documentation, it's not all that easy. Even just opening the provided Broadcom samples will yield many errors...

2.2 COMPILING SAMPLES WITH VC++ .NET
____________________________________

This is very tricky...
Assuming the base installation directory for the SDKs is : $(ProgramFiles)/WIDCOMM

2.2.1 - Mobile (BTW-CE)
-----------------------
[TO BE COMPLETED]
I have not yet written this section, but it is essentially the same as section 2.2.2. Just be careful for those pesky LNK2019 and LNK2001 errors when compiling!

For the moment, refer to:
http://blogs.msdn.com/vsdteam/archive/2 ... k2001.aspx


2.2.2 - Desktop (BTW)
---------------------

2.2.2.A
The first thing we want to do is add the proper include/lib/res directories to VC++ .NET.
In VC++ .NET's menus...

Tools » Options » Projects and Solutions » VC++ Directories

Platform: Win32
Show directories for: Include files
» Add: $(ProgramFiles)/WIDCOMM/BTW DK/SDK/Inc

Show directories for: Library files
» Add: $(ProgramFiles)/WIDCOMM/BTW DK/SDK/Release


2.2.2.B
Ok... let's try to compile a sample.
Copy the sample from $(ProgramFiles)/WIDCOMM/BTW DK/SDK/Samples/BlueClient to a new location.
Let us use D:/code/BlueClient.

Open the .vcproj file within VS2005.
Attempt to compile the project.
The following error message occurs (message box):
"This application has failed to start because btwapi.dll was not found [...]"

Refer to section 3.1 for resolution...

Once the previous issue has been resolved (by copying the appropriate file), try to compile again.
The following error message occurs (VC++ output):
fatal error LNK1104: cannot open file '../../sdk/release/BtWdSdkLib.lib'

Refer to section 3.2 for resolution...

Try to compile again.
It "should" now compile properly.


3.1 - Message box: btwapi.dll was not found
___________________________________________

In order to fix this issue, you must copy ONE of the provided btwapi.dll files within Broadcom's SDK to the $(WINDOWS)/system32 directory. Two versions of the DLL are provided by Broadcom depending on your computer's architecture (32-bit -vs- 64-bit).

Refer to $(ProgramFiles)/WIDCOMM/BTW DK/Documentation/BTW_SDK_API.pdf, p.5 (pdf page 23 of 192) for more information.


3.2 - cannot open file '../../sdk/release/BtWdSdkLib.lib'
_________________________________________________________

This one is quite amusing. To resolve this issue, open the following header file:
$(ProgramFiles)/WIDCOMM/BTW DK/SDK/Inc/BtwLib.h

Within the code of this header file, relative paths are provided.
Modify the lines 26-41 of the file as follows:

26 #ifdef _WIN64
27 //#pragma comment(lib, "..//..//sdk//release//x64//BtWdSdkLib.lib")
28 #pragma comment(lib, "x64//BtWdSdkLib.lib")
29 #else
30 //#pragma comment(lib, "..//..//sdk//release//BtWdSdkLib.lib")
31 #pragma comment(lib, "BtWdSdkLib.lib")
32 #endif
33#else
34 // use this for previous compilers
35 #ifdef _WIN64
36 //#pragma comment(lib, "..//..//sdk//release//amd64//WidcommSdklib.lib")
37 #pragma comment(lib, "amd64//WidcommSdklib.lib")
38 #else
39 //#pragma comment(lib, "..//..//sdk//release//WidcommSdklib.lib")
40 #pragma comment(lib, "WidcommSdklib.lib")
41 #endif

*** NOTE: This will only work if the $(ProgramFiles)/WIDCOMM/BTW DK/SDK/Release directory has been added to the VC++'s include directories as mentioned in section 2.2.2.A

Try to compile.
The error should now have disappeared.


Still getting that annoying erorr message?

The same LNK1104 error message "may" reappear. What now?
In VC++'s "Solution Explorer", right-click on the current project and select "Properties"
Modify the relative paths in the following sections to the $(Program Files)/.../ format:

» Configuration Properties...

» C/C++ » General » Additional Include Directories
Old value: ../../sdk/inc,../../../include
New value: $(ProgramFiles)/WIDCOMM/BTW DK/SDK/Inc

» Linker » General » Additional Library Directories
Old value: ../../sdk/release
New value: $(ProgramFiles)/WIDCOMM/BTW DK/SDK/Release

» Resources » General » Additional Include Directories
Old value: ../../sdk/inc
New value: $(ProgramFiles)/WIDCOMM/BTW DK/SDK/Inc

Voilà!


*** Additional notes ***
For information regarding the classes/methods used to code with the SDKs, refer to the provided API documentation found at the following locations:
- For BTW-CE: $(ProgramFiles)/WIDCOMM/WIDCOMM BTW-CE SDK/Documentation
- For BTW (Desktop): $(ProgramFiles)/WIDCOMM/BTW DK/Documentation

This documentation is actually quite good and describes how the various methods use Windows Messages to communicate with your application; USE THE SAMPLES to understand how this works!!! Since I'm working on an FTP application, I chose to look at the BlueClient application.

However, there are a few issues that don't seem to be documented...

1. christ2007... I'm having the same issue you've described, i.e. the Widcomm SDK inquiry process takes EXACTLY 12 seconds, no more, no less. Has anybody found further information as to why and how to "fix" this?

2. Well, it seems as though the StartDiscovery(...) and OnDiscoveryComplete(...) methods can only be used regarding ONE device at a time... if you have a list of devices (CDeviceInfo) and want to StartDiscovery(...) on them all at the same time in order to search for a specific service on each and every one of them, as an example... forget it! OnDiscoveryComplete(...) will only be triggered ONCE until the current discovery is complete... that is, YOU CAN ONLY DO ONE DISCOVERY AT A TIME! Try implementing this as a linked list and use the OnDiscoveryComplete() call to trigger the discovery on the next device instead!


P.S. : the samples seem to use Multi-byte... NOT Unicode! I think...

Hope this answers a few questions... at least I know it would've for me if I had found such a post when starting my project... Thanks to everyone who post things like this! It's always good to see people helping the community!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章