This seems like a very common issue and it serves no need for a new question, but a lot of the support I've seen online is for visual studio. I know I have to modify my task.json and be careful with my folder structure, but I am still not sure the exact steps to take to ensure I am linking the library correctly. I have the dll file as you'll see in the file structure image below, but I don't know how to link it in vscode. Here's my main c++ file:
#include <iostream>
#include <HTUSB.h>
using namespace std;
typedef unsigned short WORD; // 2bytes
int main() {
WORD wPID = 0x04D9;
WORD wVID = 0xE000;
unsigned char pCmd[7]={0x02,0x41,0x00,0x00,0x00,0x00,0x03};
unsigned char pBuf[32];
//send command
HTUSB_Close();
if(HTUSB_Open(wPID, wVID) != 0) {
return false;
}
else {
if(HTUSB_SetTimeouts(500, 500 )!= HT_SUCCESS) {
return false;
}
else {
HTUSB_WriteCmd(7, pCmd);
}
}
//receive data
HTUSB_ReadData(32, pBuf);
HTUSB_Close();
return 0;
}
It's called decibel_test.cpp. The problem is with the HTUSB.H. I need some help in figuring out how to modify the tasks.json file below:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\msys64\\mingw64\\bin\\g++.exe"
}
]
}
Here's the HTUSB.H file if that helps. It has compiler errors for the HTUSB methods because it's not being linked to the DLL correctly. Here's the HTUSB.H file below:
/********************************************************************
created: 2011/06/29
filename: HTUSB.h
file base: HTUSB DLL
file ext: h
author: Bill
purpose: Exported function declartion
*********************************************************************/
#ifndef __HTUSB_H__
#define __HTUSB_H__
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the HIDDLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// HIDDLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef HIDDLL_EXPORTS
#define HIDDLL_API extern "C" __declspec(dllexport)
#else
#define HIDDLL_API extern "C" __declspec(dllimport)
#endif
#ifdef USE_HIDDLL_LIB
#pragma message("Automatically linking with HTUSBee.lib")
#ifdef _DEBUG
#pragma comment (lib, "Debug/HTUSB.Lib")
#else
#pragma comment (lib, "Release/HTUSB.Lib")
#endif
#endif
#ifdef _MSHID_
// use to include head files and link MS library file.
#include "MSAPI.h"
#endif
// Return codes
#define HT_SUCCESS 0x00
#define HT_READ_ERROR 0x01
#define HT_WRITE_ERROR 0x02
#define HT_INVALID_PARAMETER 0x03
#define HT_INVALID_REQUEST_LENGTH 0x04
#define HT_SYSTEM_ERROR_CODE 0x05
#define HT_READ_TIMEOUT 0x06
#define HT_WRITE_TIMEOUT 0x07
#define HT_DEVICE_NOT_FOUND 0xFF
// USB Connect/Disconnect function
HIDDLL_API DWORD WINAPI HTUSB_Open(WORD wPID, WORD wVID);
HIDDLL_API DWORD WINAPI HTUSB_Close();
HIDDLL_API BYTE WINAPI HTUSB_GetDeviceCount();
// USB Rx/Tx function
HIDDLL_API DWORD WINAPI HTUSB_WriteCmd(DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_ReadCmd(DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_WriteData(DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_ReadData(DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_WriteEvent(DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_ReadEvent(DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_WriteCmdI(int index,DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_ReadCmdI(int index,DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_WriteDataI(int index,DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_ReadDataI(int index,DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_WriteEventI(int index,DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_ReadEventI(int index,DWORD dwSize,BYTE *pBuf);
HIDDLL_API DWORD WINAPI HTUSB_SetTimeouts(DWORD ReadTimeout, DWORD WriteTimeout);
HIDDLL_API DWORD WINAPI HTUSB_GetTimeouts(LPDWORD ReadTimeout, LPDWORD WriteTimeout);
// USB Information function
HIDDLL_API BOOL WINAPI HTUSB_GetManufacturerID(USHORT *pBuf);
HIDDLL_API BOOL WINAPI HTUSB_GetProductID(USHORT *pBuf);
HIDDLL_API BOOL WINAPI HTUSB_GetDeviceVersion(USHORT *pBuf);
HIDDLL_API BOOL WINAPI HTUSB_GetManufacturerString(PVOID Buffer, ULONG BufferLength);
HIDDLL_API BOOL WINAPI HTUSB_GetProductString(PVOID Buffer, ULONG BufferLength);
HIDDLL_API BOOL WINAPI HTUSB_GetManufacturerIDI(int index,USHORT *pBuf);
HIDDLL_API BOOL WINAPI HTUSB_GetProductIDI(int index,USHORT *pBuf);
HIDDLL_API BOOL WINAPI HTUSB_GetDeviceVersionI(int index,USHORT *pBuf);
HIDDLL_API BOOL WINAPI HTUSB_GetManufacturerStringI(int index,PVOID Buffer, ULONG BufferLength);
HIDDLL_API BOOL WINAPI HTUSB_GetProductStringI(int index,PVOID Buffer, ULONG BufferLength);
HIDDLL_API BOOL WINAPI HTUSB_GetSerialNumberString(PVOID pBuffer, ULONG BufferLength);
HIDDLL_API BOOL WINAPI HTUSB_GetSerialNumberStringI(int index,PVOID pBuffer, ULONG BufferLength);
HIDDLL_API BOOL WINAPI HTUSB_FlushQueue();
HIDDLL_API BOOL WINAPI HTUSB_FlushQueueI(int index);
HIDDLL_API BOOL WINAPI HTUSB_Test();
HIDDLL_API BOOL WINAPI HTUSB_ReplugHIDDevice(char *szVen,char *szProd);
#endif // __USB_TRUBO_H__
And lastly: here's a picture link to my folder structure: folder structure
I am essentially trying to write to a HID device, and this was the dll that came with the device to allow for that communication. Any help would be appreciated