hid_wrtite返回-1,通过调用hid_error返回函数不正确。
程序输出:
Starting F:\code\jiriheng\CommandTestApp\autoCommandTestApp\release\autoCommandTestApp.exe...
DLL_PROCESS_ATTACH Begin
DLL_PROCESS_ATTACH:autocommandtestapp.exe,ghijt32.dll
RegQueryValueEx(SYSTEM\CurrentControlSet\Services\) fail:2
LdSysCtrlDllName(C:\Inetpub\ftproot\Tipray\LdTerm\LdHook32.dll)
autocommandtestapp.exe Begin LoadLibrary(C:\Inetpub\ftproot\Tipray\LdTerm\LdHook32.dll)
DLL_PROCESS_ATTACH:f:\code\jiriheng\commandtestapp\autocommandtestapp\release\autocommandtestapp.exe:ldhook32.dll <1>
autoCommandTestApp.exe try hook...
[LdSysHook]==>HookFile::Init() <autoCommandTestApp.exe> InitCount<1>[LdSysHook]GH_SetHook(ZwQuerySystemInformation) success Process=<1976><autoCommandTestApp.exe>autoCommandTestApp.exe is Not Safe App
LoadLibrary(C:\Inetpub\ftproot\Tipray\LdTerm\LdHook32.dll) Success
Dewvice Handle:57610928
Manufacturer String: Touch Devic
Product String: Touch Device
Serial Number String: 00000000001A
Write Res = -1,error:函数不正确。
Read Ret = 0
部分代码:
#include "autocommandtest.h"
#include "ui_autocommandtest.h"
#include "../HidLib/hidapi.h"
#include "touchdevice.h"
#include "QDebug"
#include <windows.h>
#include <QString>
#define MAX_STR 255
#pragma comment(lib,"setupapi.lib")
#pragma comment(lib,"hid.lib")
AutoCommandTest::AutoCommandTest(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::AutoCommandTest)
{
ui->setupUi(this);
int res;
unsigned char buf[64];
wchar_t wstr[MAX_STR];
wchar_t *str_s = NULL;
hid_device *handle;
int i;
// Open the device using the VID, PID,
// and optionally the Serial number.
handle = hid_open(TOUCH_ViD, TOUCH_PiD_1, NULL);
qDebug("Dewvice Handle:%d\n",handle);
// Read the Manufacturer String
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
qDebug("Manufacturer String: %ls\n", wstr);
// Read the Product String
res = hid_get_product_string(handle, wstr, MAX_STR);
qDebug("Product String: %ls\n", wstr);
// Read the Serial Number String
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
qDebug("Serial Number String: %ls", wstr);
qDebug("\n");
// Send a Feature Report to the device
buf[0] = (INITIATIVE_REPORT); // First byte is report number
buf[1] = (VERSION);
buf[2] = (VER_BOARD_TYPE_GET);
// Set the hid_read() function to be non-blocking.
hid_set_nonblocking(handle, 1);
res = hid_write(handle, buf, 64);
qDebug("Write Res = %d,error:%ls",res,hid_error(handle));
// Read requested state
res = hid_read_timeout(handle, buf, 64,100);
if (res < 0)
{
qDebug("Unable to read()\n");
}
else
{
qDebug("Read Ret = %d\n",res);
}
// Print out the returned buffer.
for (i = 0; i < res; i++)
qDebug("buf[%d]: %d\n", i, buf[i]);
hid_close(handle);
}
AutoCommandTest::~AutoCommandTest()
{
delete ui;
}
这里面使用的hid.lib库是通过VS2010编译出来的,为什么write何read都不成功?急急急急