Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: Calling C.SetEvent() with an event from C returns an invalid handler (error code 6) #44807

Closed
FWidel opened this issue Mar 5, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@FWidel
Copy link

FWidel commented Mar 5, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOHOSTARCH=amd64
set GOHOSTOS=windows

What did you do?

I created event in C:

 sg_hEventRecv = CreateEvent(nullptr, FALSE, FALSE, nullptr);
 VSCAN_SetRcvEvent(1, sg_hEventRecv)

Then I tried to use this event in cgo:

var event C.HANDLE
func signalState(){
C.SetEvent(event) 
}

//export VSCAN_SetRcvEvent
func VSCAN_SetRcvEvent(Handle VSCAN_HANDLE, Event C.HANDLE) int {
    event = Event
    return 0
}

What did you expect to see?

To be able to call C.SetEvent(event), with event passed directly from C

What did you see instead?

error code 6 (invalid handler).

@AlexRouSg
Copy link
Contributor

Please provide a complete runable example.
The following test program runs without error.

package main

/*
#include <windows.h>
#include <synchapi.h>

extern void VSCAN_SetRcvEvent(HANDLE);

static void test() {
	VSCAN_SetRcvEvent(CreateEvent(NULL, 0, 0, NULL));
}
*/
import "C"
import (
	"fmt"
)

var event C.HANDLE

func main() {
	C.test()

	if C.SetEvent(event) == 0 {
		fmt.Printf("%x\n", C.GetLastError())
	}
}

//export VSCAN_SetRcvEvent
func VSCAN_SetRcvEvent(Event C.HANDLE) {
	event = Event
}

@toothrot toothrot added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Mar 8, 2021
@toothrot toothrot changed the title Calling C.SetEvent() with an event from C returns an invalid handler (error code 6) cmd/cgo: Calling C.SetEvent() with an event from C returns an invalid handler (error code 6) Mar 8, 2021
@toothrot toothrot added this to the Backlog milestone Mar 8, 2021
@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants