Closed kkevinchou closed 4 months ago
@kkevinchou your nil check is wrong. payload != nil
checks if go wrapper is nil, but the actual thing you want not t be nil is payload.CData
.
I'm sorry tha it is this way but thats because of GO.
its like this:
type Payload struct {
CData *C.ImGuiPayload
}
because if it was simply type Payload *C.ImGuiPayload
go complains that "invalid receiver type foo (pointer or interface type)"
I hope this helped ;-)
thanks! that clarifies things. how would I be able to extract the actual "hello"
text in my example? i've tried to cast the unsafe.Pointer
into a (*string) but I'm getting an empty string back:
fmt.Println(*(*string)(payload.CData.Data))
@kkevinchou Your method of converting uintptr to string pointer is right. Whats wrong in your code is the sz
arg in SetDragDropPayload
. This should be a memory size of your string, not its len, so len(s)* sizeof(rune)
.
Go has a nice way to calculate this: unsafe.Sizeof(s)
will work.
that was my issue, thanks for the help!
hello, I've been stuck trying to get drag and drop working. If anyone could provide a small working example that'd be greatly appreciated
I've been messing around with various forms of:
my goal is to be able to read out the "hello" string on the receiving end, but it causes a crash like this (i added the above example code to the example in this project)