mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
fixes Errors when unplug device on windows Issue #95
This commit is contained in:
parent
b38b3e53ea
commit
1e1463bfdf
1 changed files with 15 additions and 0 deletions
|
|
@ -10,6 +10,10 @@
|
|||
|
||||
#define MAX_BUFFER_SIZE 1000
|
||||
|
||||
// Declare type of pointer to CancelIoEx function
|
||||
typedef BOOL (WINAPI *CancelIoExType)(HANDLE hFile, LPOVERLAPPED lpOverlapped);
|
||||
|
||||
|
||||
std::list<int> g_closingHandles;
|
||||
int bufferSize;
|
||||
void ErrorCodeToString(const char* prefix, int errorCode, char *errorStr) {
|
||||
|
|
@ -310,6 +314,17 @@ void EIO_Close(uv_work_t* req) {
|
|||
CloseBaton* data = static_cast<CloseBaton*>(req->data);
|
||||
|
||||
g_closingHandles.push_back(data->fd);
|
||||
|
||||
HMODULE hKernel32 = LoadLibrary("kernel32.dll");
|
||||
// Look up function address
|
||||
CancelIoExType pCancelIoEx = (CancelIoExType)GetProcAddress(hKernel32, "CancelIoEx");
|
||||
// Do something with it
|
||||
if (pCancelIoEx)
|
||||
{
|
||||
// Function exists so call it
|
||||
// Cancel all pending IO Requests for the current device
|
||||
pCancelIoEx((HANDLE)data->fd, NULL);
|
||||
}
|
||||
if(!CloseHandle((HANDLE)data->fd)) {
|
||||
ErrorCodeToString("closing connection", GetLastError(), data->errorString);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue