From ce056b9f228550b0961693ea31dbfbf3251c9028 Mon Sep 17 00:00:00 2001 From: Xiang Shi <33132228+KevinZonda@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:14:17 +0100 Subject: [PATCH 1/3] Replace C.DWORD due to not compiling --- usb_winusb.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/usb_winusb.go b/usb_winusb.go index 3304688..6c1dc54 100644 --- a/usb_winusb.go +++ b/usb_winusb.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build windows // +build windows package main @@ -34,26 +35,28 @@ var device struct { mtx sync.Mutex } -func (e C.DWORD) Error() string { +type C_DWORD C.ulong + +func (e C_DWORD) Error() string { return fmt.Sprintf("Windows Error: 0x%x", uint(e)) } const ( - SUCCESS C.DWORD = C.ERROR_SUCCESS - ERROR_INVALID_STATE C.DWORD = C.ERROR_INVALID_STATE - ERROR_INVALID_HANDLE C.DWORD = C.ERROR_INVALID_HANDLE - ERROR_INVALID_PARAMETER C.DWORD = C.ERROR_INVALID_PARAMETER - ERROR_OUTOFMEMORY C.DWORD = C.ERROR_OUTOFMEMORY - ERROR_GEN_FAILURE C.DWORD = C.ERROR_GEN_FAILURE - ERROR_OBJECT_NOT_FOUND C.DWORD = C.ERROR_OBJECT_NOT_FOUND - ERROR_NOT_SUPPORTED C.DWORD = C.ERROR_NOT_SUPPORTED - ERROR_SHARING_VIOLATION C.DWORD = C.ERROR_SHARING_VIOLATION - ERROR_BAD_COMMAND C.DWORD = C.ERROR_BAD_COMMAND + SUCCESS C_DWORD = C.ERROR_SUCCESS + ERROR_INVALID_STATE C_DWORD = C.ERROR_INVALID_STATE + ERROR_INVALID_HANDLE C_DWORD = C.ERROR_INVALID_HANDLE + ERROR_INVALID_PARAMETER C_DWORD = C.ERROR_INVALID_PARAMETER + ERROR_OUTOFMEMORY C_DWORD = C.ERROR_OUTOFMEMORY + ERROR_GEN_FAILURE C_DWORD = C.ERROR_GEN_FAILURE + ERROR_OBJECT_NOT_FOUND C_DWORD = C.ERROR_OBJECT_NOT_FOUND + ERROR_NOT_SUPPORTED C_DWORD = C.ERROR_NOT_SUPPORTED + ERROR_SHARING_VIOLATION C_DWORD = C.ERROR_SHARING_VIOLATION + ERROR_BAD_COMMAND C_DWORD = C.ERROR_BAD_COMMAND ) -func winusbError(err error) error { - if err != SUCCESS { - return err +func winusbError(err C.ulong) error { + if err != C.ERROR_SUCCESS { + return C_DWORD(err) } return nil } From f2616136e620b50f5dfa9b269adccb54906f8f97 Mon Sep 17 00:00:00 2001 From: Xiang Shi <33132228+KevinZonda@users.noreply.github.com> Date: Wed, 24 Apr 2024 20:16:20 +0100 Subject: [PATCH 2/3] Update usb_winusb.go Co-authored-by: George Spalding --- usb_winusb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb_winusb.go b/usb_winusb.go index 6c1dc54..cff686a 100644 --- a/usb_winusb.go +++ b/usb_winusb.go @@ -35,7 +35,7 @@ var device struct { mtx sync.Mutex } -type C_DWORD C.ulong +type C_DWORD C.DWORD func (e C_DWORD) Error() string { return fmt.Sprintf("Windows Error: 0x%x", uint(e)) From 8b5ed83581da044f35ad237e852934a984be70fa Mon Sep 17 00:00:00 2001 From: Xiang Shi <33132228+KevinZonda@users.noreply.github.com> Date: Wed, 24 Apr 2024 20:18:45 +0100 Subject: [PATCH 3/3] rename C.ulong to C.DWORD --- usb_winusb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb_winusb.go b/usb_winusb.go index cff686a..aa527ed 100644 --- a/usb_winusb.go +++ b/usb_winusb.go @@ -54,7 +54,7 @@ const ( ERROR_BAD_COMMAND C_DWORD = C.ERROR_BAD_COMMAND ) -func winusbError(err C.ulong) error { +func winusbError(err C.DWORD) error { if err != C.ERROR_SUCCESS { return C_DWORD(err) }