Bluetooth connection error with winsock2.h

I am completely new to socket programming or any kind of API for that. I want to learn to connect to a bluetooth device. I have allergy of C# style codes so, I dug up a sample code that uses winsock.This is the sample [url][/url]. The sample is pretty good and easy to understand.

Problem occurs when I run it. For a simple test, I paired a bluetooth earphone to my PC and ran the sample code as is. It throws error 10049 at line 381. For some reason the connect() is failing.

Can anyone point out the reason for it? And if there is any solution or some other similar method of connecting to bluetooth devices (I would prefer something simple and low-level method, not .NET managed method), please.

Thank you.

I am using MSVS2022, c++14 standard (c++20 gives compiler error).
Last edited on
C++20 can break code that worked with an earlier standard if there are any comparisons -- <, > or something similar -- being made.

Does setting the standard to C++17 also bomb out?

There are no URL tags here at CPlusPlus, so the forum's URL interpreter borks up the link you posted. Just slap the URL in place on a line by itself or with some whitespace after the URL to work.

At a quick glance that code doesn't need to be C++ code, if you set the file's extension to .c it might not error out.

VS defaults to classic MS C with a C source file, IIRC that is C99 standard.

That is a last resort, though.

The code may not be usable now no matter what you do, MS has made some changes to the WinAPI over the years. This is a "classic sample" for Win 7.
Last edited on
@George P, Thanks for the response. The code compiles with c++17. It can find the device and address etc. But when I try to connect to the device, it gives error. I was looking for a way to connect to bluetooth devices without using the managed code examples. The other sample codes I found are all .NET managed codes. Is there any low-level methods like this for windows 10? Or more specifically, a simple method unlike using Windows's Bluetooth and Generic namespaces.
Last edited on
Topic archived. No new replies allowed.