diff --git a/README.md b/README.md index 314bf06..f1efd93 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,74 @@ This repository is a sample on how to connect from a Windows 10 PC to an ESP32 v * Helpful examples on getting connected devices - https://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedotherprotocol4k.html * Bluetooth APIs - https://docs.microsoft.com/en-us/windows/win32/api/bluetoothapis/ * Microsoft example - https://github.com/microsoftarchive/msdn-code-gallery-microsoft/blob/master/Official%20Windows%20Platform%20Sample/Bluetooth%20connection%20sample/%5BC%2B%2B%5D-Bluetooth%20connection%20sample/C%2B%2B/bthcxn.cpp -* Bluetooth programming with Windows sockets - https://docs.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-programming-with-windows-sockets \ No newline at end of file +* Bluetooth programming with Windows sockets - https://docs.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-programming-with-windows-sockets + +## 2024 Addendum + +When running this in 2024, with Visual Studio 2024 on a Windows 11 device, I encountered the following issues: + + +### Download C++ Tools for Visual Studio 2022 + +When I first loaded the project, I needed to install the C++ development tools. That was easy. + +### Wasn't Linking Ws2_32.lib + +Then I built the project, and encountered the following errors: + +``` +Build started... +1>------ Build started: Project: WindowsBtWithEsp32, Configuration: Debug x64 ------ +1>WindowsBtWithEsp32.cpp +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_closesocket referenced in function "bool __cdecl sendMessageToEsp32(void)" (?sendMessageToEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_connect referenced in function "bool __cdecl connectToEsp32(void)" (?connectToEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_ioctlsocket referenced in function "bool __cdecl connectToEsp32(void)" (?connectToEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_recv referenced in function "bool __cdecl recieveMessageFromEsp32(void)" (?recieveMessageFromEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_send referenced in function "bool __cdecl sendMessageToEsp32(void)" (?sendMessageToEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_socket referenced in function "bool __cdecl connectToEsp32(void)" (?connectToEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_WSAStartup referenced in function "bool __cdecl startupWindowsSocket(void)" (?startupWindowsSocket@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_WSACleanup referenced in function "bool __cdecl sendMessageToEsp32(void)" (?sendMessageToEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol __imp_WSAGetLastError referenced in function "bool __cdecl connectToEsp32(void)" (?connectToEsp32@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol BluetoothFindFirstDevice referenced in function "bool __cdecl getPairedEsp32BtAddress(void)" (?getPairedEsp32BtAddress@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol BluetoothFindNextDevice referenced in function "bool __cdecl getPairedEsp32BtAddress(void)" (?getPairedEsp32BtAddress@@YA_NXZ) +1>C:\dev\bluetooth-windows-esp32-example\WindowsBtWithEsp32\x64\Debug\WindowsBtWithEsp32.exe : fatal error LNK1120: 11 unresolved externals +1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(1127,5): error MSB6006: "link.exe" exited with code 1120. +1>Done building project "WindowsBtWithEsp32.vcxproj" -- FAILED. +========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== +========== Build started at 8:07 PM and took 03.596 seconds ========== +``` + +To fix this, I added `Ws2_32.lib` into my Additional Dependencies. As described in this [stack overflow](https://stackoverflow.com/a/53873194) + +* Right click on my "WindowsBtWithEsp32" project in Solution Explorer +* Click Properties +* Go to Linker => Input. Click to edit Additional Dependencies +* Add `Ws2_32.lib` in the first box: +![Adding dependency](image-1.png) + +### Didn't Have Pragma comment + +Then I built again, and received the following error: + +``` +Build started... +1>------ Build started: Project: WindowsBtWithEsp32, Configuration: Debug x64 ------ +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol BluetoothFindFirstDevice referenced in function "bool __cdecl getPairedEsp32BtAddress(void)" (?getPairedEsp32BtAddress@@YA_NXZ) +1>WindowsBtWithEsp32.obj : error LNK2019: unresolved external symbol BluetoothFindNextDevice referenced in function "bool __cdecl getPairedEsp32BtAddress(void)" (?getPairedEsp32BtAddress@@YA_NXZ) +1>C:\dev\bluetooth-windows-esp32-example\WindowsBtWithEsp32\x64\Debug\WindowsBtWithEsp32.exe : fatal error LNK1120: 2 unresolved externals +1>Done building project "WindowsBtWithEsp32.vcxproj" -- FAILED. +========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== +========== Build started at 8:12 PM and took 00.453 seconds ========== +``` + +To fix this I added this comment (`#pragma comment(lib, "Bthprops.lib")`) below my include statements + +![programming includes](image.png) + +Then I could build and run the solution: + +![sample output](image-2.png) + +## This fork now works + +This fork now contains fixes for these issues. Hopefully allowing anyone in the future to resolve these issues. \ No newline at end of file diff --git a/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.cpp b/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.cpp index d4b8317..f9cef05 100644 --- a/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.cpp +++ b/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.cpp @@ -12,6 +12,7 @@ Bluetooth programming with Windows sockets - https://docs.microsoft.com/en-us/wi #include #include #include +#pragma comment(lib, "Bthprops.lib") BTH_ADDR esp32BtAddress; SOCKADDR_BTH btSocketAddress; diff --git a/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.vcxproj b/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.vcxproj index 5bcffe6..9524e9c 100644 --- a/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.vcxproj +++ b/WindowsBtWithEsp32/WindowsBtWithEsp32/WindowsBtWithEsp32.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode @@ -121,6 +121,7 @@ Console true + Ws2_32.lib;%(AdditionalDependencies) diff --git a/image-1.png b/image-1.png new file mode 100644 index 0000000..b61b240 Binary files /dev/null and b/image-1.png differ diff --git a/image-2.png b/image-2.png new file mode 100644 index 0000000..69ff4e9 Binary files /dev/null and b/image-2.png differ diff --git a/image.png b/image.png new file mode 100644 index 0000000..6622bd3 Binary files /dev/null and b/image.png differ