本文整理汇总了C++中register_error函数的典型用法代码示例。如果您正苦于以下问题:C++ register_error函数的具体用法?C++ register_error怎么用?C++ register_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hid_open_path
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
{
hid_device *dev;
HIDP_CAPS caps;
HIDP_PREPARSED_DATA *pp_data = NULL;
BOOLEAN res;
NTSTATUS nt_res;
#ifndef HIDAPI_USE_DDK
if (!initialized)
lookup_functions();
#endif
dev = new_hid_device();
// Open a handle to the device
dev->device_handle = CreateFileA(path,
GENERIC_WRITE |GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, /*share mode*/
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
/* FILE_ATTRIBUTE_NORMAL, */
0);
// Check validity of write_handle.
if (dev->device_handle == INVALID_HANDLE_VALUE) {
// Unable to open the device.
register_error(dev, "CreateFile");
goto err;
}
// Get the Input Report length for the device.
res = HidD_GetPreparsedData(dev->device_handle, &pp_data);
if (!res) {
register_error(dev, "HidD_GetPreparsedData");
goto err;
}
nt_res = HidP_GetCaps(pp_data, &caps);
if (nt_res != HIDP_STATUS_SUCCESS) {
register_error(dev, "HidP_GetCaps");
goto err_pp_data;
}
dev->input_report_length = caps.InputReportByteLength;
HidD_FreePreparsedData(pp_data);
return dev;
err_pp_data:
HidD_FreePreparsedData(pp_data);
err:
CloseHandle(dev->device_handle);
free(dev);
return NULL;
}
示例2: hid_write
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length)
{
DWORD bytes_written;
BOOL res;
OVERLAPPED ol;
unsigned char *buf;
memset(&ol, 0, sizeof(ol));
/* Make sure the right number of bytes are passed to WriteFile. Windows
expects the number of bytes which are in the _longest_ report (plus
one for the report number) bytes even if the data is a report
which is shorter than that. Windows gives us this value in
caps.OutputReportByteLength. If a user passes in fewer bytes than this,
create a temporary buffer which is the proper size. */
if (length >= dev->output_report_length) {
/* The user passed the right number of bytes. Use the buffer as-is. */
buf = (unsigned char *) data;
} else {
/* Create a temporary buffer and copy the user's data
into it, padding the rest with zeros. */
buf = (unsigned char *) malloc(dev->output_report_length);
memcpy(buf, data, length);
memset(buf + length, 0, dev->output_report_length - length);
length = dev->output_report_length;
}
res = WriteFile(dev->device_handle, buf, length, NULL, &ol);
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
/* WriteFile() failed. Return error. */
register_error(dev, "WriteFile");
bytes_written = -1;
goto end_of_function;
}
}
/* Wait here until the write is done. This makes
hid_write() synchronous. */
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_written, TRUE/*wait*/);
if (!res) {
/* The Write operation failed. */
register_error(dev, "WriteFile");
bytes_written = -1;
goto end_of_function;
}
end_of_function:
if (buf != data)
free(buf);
return bytes_written;
}
示例3: hid_write
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length)
{
DWORD bytes_written;
BOOL res;
static OVERLAPPED ol;
Check_For_Result:
if(!dev->blocking && dev->ioPending)
{
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_written, FALSE/*don't wait*/);
if(!res)
{
return 0;
}
else
{
dev->ioPending = false;
return bytes_written;
}
}
memset(&ol, 0, sizeof(ol));
res = WriteFile(dev->device_handle, data, length, &bytes_written, &ol);
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
// WriteFile() failed. Return error.
register_error(dev, "WriteFile");
return -1;
}
}
if(!dev->blocking)
{
dev->ioPending = true;
goto Check_For_Result;
}
else
{
// Wait here until the write is done. This makes
// hid_write() synchronous.
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_written, TRUE/*wait*/);
if (!res) {
// The Write operation failed.
register_error(dev, "WriteFile");
return -1;
}
}
return bytes_written;
}
示例4: hid_open_path
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
{
hid_device *dev;
HIDP_CAPS caps;
HIDP_PREPARSED_DATA *pp_data = NULL;
BOOLEAN res;
NTSTATUS nt_res;
#ifndef HIDAPI_USE_DDK
if (!initialized)
lookup_functions();
#endif
dev = new_hid_device();
// Open a handle to the device
dev->device_handle = open_device(path);
// Check validity of write_handle.
if (dev->device_handle == INVALID_HANDLE_VALUE) {
// Unable to open the device.
register_error(dev, "CreateFile");
goto err;
}
// Get the Input Report length for the device.
res = HidD_GetPreparsedData(dev->device_handle, &pp_data);
if (!res) {
register_error(dev, "HidD_GetPreparsedData");
goto err;
}
nt_res = HidP_GetCaps(pp_data, &caps);
if (nt_res != HIDP_STATUS_SUCCESS) {
register_error(dev, "HidP_GetCaps");
goto err_pp_data;
}
dev->input_report_length = caps.InputReportByteLength;
HidD_FreePreparsedData(pp_data);
dev->read_buf = (char*) malloc(dev->input_report_length);
return dev;
err_pp_data:
HidD_FreePreparsedData(pp_data);
err:
CloseHandle(dev->device_handle);
free(dev);
return NULL;
}
示例5: allot
Pfstream_handle *pfstream_start_write_thread(char *fname)
{
Pfstream_handle *pfh; /* Handle downstream functions can use to
access data from the pfstream */
Pfstream_control *pfsc; /* control structure passed to new thread */
/*These need to be created fromt he free store. If we
used a local variable in this function these would disappear when
this routine went out of scope screwing up the thread it was passed
to, and the return handle would get dropped.*/
allot(Pfstream_handle *,pfh,1);
allot(Pfstream_control *, pfsc, 1);
/* brttutil routine to create a multithreaded, posix compatible thread */
pfh->mtf = pmtfifo_create(PFSTREAM_MAXQUEUE,1,0);
if(pfh->mtf == NULL)
{
register_error(1,"pfstream_start_write_thead: Could not create mtfifo\n");
free(pfh);
free(pfsc);
return(NULL);
}
pfsc->mtf=pfh->mtf;
/* open the stream and put the fp into the control structure */
pfsc->fp = fopen(fname,"r+");
if(pfsc->fp==NULL)
{
register_error(1,"pfstream_start_write_thread: Cannot open output stream %s\n",
fname);
pmtfifo_destroy(pfh->mtf,free);
free(pfh);
free(pfsc);
return(NULL);
}
/* This launches the write thread. This is assumed to do the
opposite of the read thread. That is, processing modules will
push data onto this mtfifo and the write routine handled by
this thread will pop them off and send the contents down the
stream now open as fp */
if(pthread_create(&(pfh->thread_id),NULL,pfstream_write_data,(void *)pfsc)!=0)
{
register_error(1,"pfstream_start_write_thread: cannot create write thread\n");
pmtfifo_destroy(pfh->mtf,free);
fclose(pfsc->fp);
free(pfh);
free(pfsc);
return(NULL);
}
return(pfh);
}
示例6: hid_open_path
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
{
hid_device *dev;
HIDP_CAPS caps;
PHIDP_PREPARSED_DATA pp_data = NULL;
BOOLEAN res;
NTSTATUS nt_res;
if (hid_init() < 0) {
return NULL;
}
dev = new_hid_device();
/* Open a handle to the device */
dev->device_handle = open_device(path, FALSE);
/* Check validity of write_handle. */
if (dev->device_handle == INVALID_HANDLE_VALUE) {
/* Unable to open the device. */
register_error(dev, "CreateFile");
goto err;
}
/* Get the Input Report length for the device. */
res = HidD_GetPreparsedData(dev->device_handle, &pp_data);
if (!res) {
register_error(dev, "HidD_GetPreparsedData");
goto err;
}
nt_res = HidP_GetCaps(pp_data, &caps);
if (nt_res != HIDP_STATUS_SUCCESS) {
register_error(dev, "HidP_GetCaps");
goto err_pp_data;
}
dev->output_report_length = caps.OutputReportByteLength;
dev->input_report_length = caps.InputReportByteLength;
HidD_FreePreparsedData(pp_data);
dev->read_buf = (char*) malloc(dev->input_report_length);
return dev;
err_pp_data:
HidD_FreePreparsedData(pp_data);
err:
CloseHandle(dev->device_handle);
free(dev);
return NULL;
}
示例7: log2orbpkt
int
log2orbpkt (char *comment, char **packet, int *nbytes, int *bufsize)
{
int comment_length;
unsigned short hdrsiz;
unsigned short pktsiz;
int bsize;
unsigned short int usi;
char *ptr;
comment_length = strlen(comment);
hdrsiz = 2 + 2 + 2 + 2;
pktsiz = hdrsiz + comment_length + 1;
*nbytes = pktsiz;
bsize = *nbytes + 1;
if (*packet == NULL) {
*packet = (char *) malloc (bsize);
if (*packet == NULL) {
register_error (1, "log2orbpkt: malloc() error.\n");
return (-1);
}
*bufsize = bsize;
} else if (bsize > *bufsize) {
*packet = (char *) realloc (*packet, bsize);
if (*packet == NULL) {
register_error (1, "log2orbpkt: realloc() error.\n");
return (-1);
}
*bufsize = bsize;
}
ptr = *packet;
H2N2 (ptr, &hdrsiz, 1);
ptr += 2;
H2N2 (ptr, &pktsiz, 1);
ptr += 2;
usi = (unsigned short int)QUANTERRA_LOG_HDR_TYPE;
H2N2 (ptr, &usi, 1);
ptr += 2;
usi = (unsigned short int)QUANTERRA_LOG_PKT_TYPE;
H2N2 (ptr, &usi, 1);
ptr += 2;
memcpy (ptr, comment, (int)comment_length + 1);
/* normal exit */
return (0);
}
示例8: setupqorbpkt
int
setupqorbpkt ()
{
if (register_pkt_handler (QUANTERRA_DATA_PKT_TYPE, NULL, unstuffqorbpkt) < 0) {
register_error (0, "setupqorbpkt: register_pkt_handler() error.\n");
return (-1);
}
if (register_pkt_handler (QUANTERRA_DATA_PKT_TYPE2, NULL, unstuffqorbpkt) < 0) {
register_error (0, "setupqorbpkt: register_pkt_handler() error.\n");
return (-1);
}
return (0);
}
示例9: hid_get_feature_report
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
BOOL res;
#if 0
res = HidD_GetFeature(dev->device_handle, (PVOID)data, (ULONG)length);
if (!res) {
register_error(dev, "HidD_GetFeature");
return -1;
}
return 0; /* HidD_GetFeature() doesn't give us an actual length, unfortunately */
#else
DWORD bytes_returned;
OVERLAPPED ol;
memset(&ol, 0, sizeof(ol));
res = DeviceIoControl(dev->device_handle,
IOCTL_HID_GET_FEATURE,
data, (DWORD)length,
data, (DWORD)length,
&bytes_returned, &ol);
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
/* DeviceIoControl() failed. Return error. */
register_error(dev, "Send Feature Report DeviceIoControl");
return -1;
}
}
/* Wait here until the write is done. This makes
hid_get_feature_report() synchronous. */
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_returned, TRUE/*wait*/);
if (!res) {
/* The operation failed. */
register_error(dev, "Send Feature Report GetOverLappedResult");
return -1;
}
/* bytes_returned does not include the first byte which contains the
report ID. The data buffer actually contains one more byte than
bytes_returned. */
bytes_returned++;
return bytes_returned;
#endif
}
示例10: hid_read_timeout
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
{
DWORD bytes_read = 0;
size_t copy_len = 0;
BOOL res;
/* Copy the handle for convenience. */
HANDLE ev = dev->ol.hEvent;
if (!dev->read_pending) {
/* Start an Overlapped I/O read. */
dev->read_pending = TRUE;
memset(dev->read_buf, 0, dev->input_report_length);
ResetEvent(ev);
res = ReadFile(dev->device_handle, dev->read_buf, dev->input_report_length, &bytes_read, &dev->ol);
if (!res) {
DWORD er = GetLastError();
if (GetLastError() != ERROR_IO_PENDING) {
/* ReadFile() has failed.
Clean up and return error. */
CancelIo(dev->device_handle);
dev->read_pending = FALSE;
goto end_of_function;
}
}
}
if (milliseconds >= 0) {
/* See if there is any data yet. */
res = WaitForSingleObject(ev, milliseconds);
if (res != WAIT_OBJECT_0) {
/* There was no data this time. Return zero bytes available,
but leave the Overlapped I/O running. */
return 0;
}
}
/* Either WaitForSingleObject() told us that ReadFile has completed, or
we are in non-blocking mode. Get the number of bytes read. The actual
data has been copied to the data[] array which was passed to ReadFile(). */
res = GetOverlappedResult(dev->device_handle, &dev->ol, &bytes_read, TRUE/*wait*/);
/* Set pending back to false, even if GetOverlappedResult() returned error. */
dev->read_pending = FALSE;
if (res && bytes_read > 0) {
/* Copy the whole buffer, report number and all. */
copy_len = length > bytes_read ? bytes_read : length;
memcpy(data, dev->read_buf, copy_len);
}
end_of_function:
if (!res) {
register_error(dev, "GetOverlappedResult");
return -1;
}
return copy_len;
}
示例11: hid_get_feature_report
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
BOOL res;
#if 0
res = HidD_GetFeature(dev->device_handle, data, length);
if (!res) {
register_error(dev, "HidD_GetFeature");
return -1;
}
return 0; /* HidD_GetFeature() doesn't give us an actual length, unfortunately */
#else
DWORD bytes_returned;
OVERLAPPED ol;
memset(&ol, 0, sizeof(ol));
res = DeviceIoControl(dev->device_handle,
IOCTL_HID_GET_FEATURE,
data, length,
data, length,
&bytes_returned, &ol);
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
// DeviceIoControl() failed. Return error.
register_error(dev, "Send Feature Report DeviceIoControl");
return -1;
}
}
// Wait here until the write is done. This makes
// hid_get_feature_report() synchronous.
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_returned, TRUE/*wait*/);
if (!res) {
// The operation failed.
register_error(dev, "Send Feature Report GetOverLappedResult");
return -1;
}
// Get HID Stick messages
HID_GetStick20ReceiveData (data);
return bytes_returned;
#endif
}
示例12: hid_send_feature_report
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
{
BOOL res = HidD_SetFeature(dev->device_handle, (PVOID)data, length);
if (!res) {
register_error(dev, "HidD_SetFeature");
return -1;
}
return length;
}
示例13: hid_get_product_string
int HID_API_EXPORT_CALL HID_API_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;
res = HidD_GetProductString(dev->device_handle, string, (ULONG)(sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS)));
if (!res) {
register_error(dev, "HidD_GetProductString");
return -1;
}
return 0;
}
示例14: hid_get_indexed_string
int HID_API_EXPORT_CALL HID_API_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
{
BOOL res;
res = HidD_GetIndexedString(dev->device_handle, string_index, string, sizeof(wchar_t) * maxlen);
if (!res) {
register_error(dev, "HidD_GetIndexedString");
return -1;
}
return 0;
}
示例15: hid_get_product_string
int HID_API_EXPORT_CALL HID_API_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;
res = HidD_GetProductString(dev->device_handle, string, 2 * maxlen);
if (!res) {
register_error(dev, "HidD_GetProductString");
return -1;
}
return 0;
}