0

I have a problem with my c++ bluetooth class. I work on a school project and have to write a function that show the paired bluetooth devices. Usually I programm in other languages, therefore my c++ knowledge isn't very well.

I've got the following error messages:

LNK2019 Verweis auf nicht aufgelöstes externes Symbol "_BluetoothFindFirstDevice@8" in Funktion ""public: void __thiscall bluetooth::showPairedDevices(void)" (?showPairedDevices@bluetooth@@QAEXXZ)"

.

LNK2019 Verweis auf nicht aufgelöstes externes Symbol "_BluetoothFindNextDevice@8" in Funktion ""public: void __thiscall bluetooth::showPairedDevices(void)" (?showPairedDevices@bluetooth@@QAEXXZ)"

The sourcecode:

#pragma once
#include "iostream"
#include "stdlib.h"
#include "stdio.h"
#include "Winsock2.h"
#include "Ws2bth.h"
#include "BluetoothAPIs.h"
#include "WinBase.h"

class bluetooth
{

public:
    bluetooth();
    ~bluetooth();

    void showPairedDevices();
};

void bluetooth::showPairedDevices() {
    HBLUETOOTH_DEVICE_FIND foundedDevice;
    BLUETOOTH_DEVICE_INFO deviceInfo;
    deviceInfo.dwSize = sizeof(deviceInfo);

    BLUETOOTH_DEVICE_SEARCH_PARAMS searchCriteria;
    searchCriteria.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS);
    searchCriteria.fReturnAuthenticated = TRUE;
    searchCriteria.fReturnRemembered = FALSE;
    searchCriteria.fReturnConnected = FALSE;
    searchCriteria.fReturnUnknown = FALSE;
    searchCriteria.fIssueInquiry = FALSE;
    searchCriteria.cTimeoutMultiplier = 0;
    searchCriteria.hRadio = NULL;

    foundedDevice = BluetoothFindFirstDevice(&searchCriteria, &deviceInfo);

    if (foundedDevice == NULL) {
        std::cout << "no devices found";
    } else {
        do {
            std::cout << "founded device: " << deviceInfo.szName << std::endl;
        } while (BluetoothFindNextDevice(foundedDevice, &deviceInfo));
    }

    return;
};

Hope you can help me!

Regards

Frodo
  • 749
  • 11
  • 23
Andre
  • 1
  • 1
    In C++ including headers is not enough. You must also tell the linker where to find the libraries that implement the headers. If I remember correctly, the library paths input is on the same property page as the include paths. – user4581301 Feb 23 '16 at 08:02
  • Side note: if the header appears in more than one obj file, you will get multiple definition error as well; use `inline` on the function definition outside the class definition `inline void bluetooth::showPairedDevices()` – Niall Feb 23 '16 at 08:23
  • If `BluetoothFindFirstDevice` is defined in a C library, you will need to add the `extern "C"` to get the name mangling correct as well. – Niall Feb 23 '16 at 08:24
  • I'm going to mark this as a duplicate, I believe the duplicate covers the possible errors in this case, in particular linking the lib, the mangled name vs C imported name. – Niall Feb 23 '16 at 08:28
  • But how I tell the linker, where the libraries are? – Andre Feb 23 '16 at 10:58
  • Ok I have added the following line: `#pragma comment(lib, "irprops.lib")` Now it works! Thank you! – Andre Feb 23 '16 at 11:55

0 Answers0