c++hidhidapi

HidD_SetOutputReport not resolved


I'm trying to interface with a device I found that uses the hid protocol. I'm using signal11's hidapi, and c++, however I'm writing to the device using hidsdi.h, specifically HidD_SetOutputReport, however, this results in "LNK2019: unresolved external symbol HidD_SetOutputReport referenced in function main"

Here is my code:

#include <string>
#include <Windows.h>
#include "hidapi.h"
extern "C"
{
    #include <hidsdi.h>
};

using namespace std;

int main()
{
    wchar_t output[255];
    hid_device* portal = NULL;
    
    int result = hid_init();
    portal = hid_open(0x1430, 0x0150, NULL);
    hid_get_product_string(portal, output, 255);
    wprintf(L"product: %s\n", output);
    unsigned char data[0x21];
    memset(data, 0, 0x21);
    data[0] = 0x0;
    data[1] = 0x0B;
    data[2] = 0x14;
    data[3] = 'R';
    if(HidD_SetOutputReport(portal, data, 0x21))
    {
        cout << "write succeeded";
    }
    else
    {
        cout << "write failed";
    }
    hid_exit();
}

If anyone knows the answer to this it would be much appreciated, thanks in advance!

PS: I'm on Windows and am using visual studio 2019 if that helps


Solution

  • You must link your program with Hid.lib.

    Go to project settings / linker and add it to all targets.