On Tue, Aug 29, 2017 at 8:53 AM, Phil Noel <p...@noels.org.uk> wrote: > > I believe the error is that _cgoCheckPointer is scanning the _cgo0 variable > (ie c_msg, ie type *_Ctype_struct_tagMSG) and detecting the > hwnd:(win._Ctype_HWND)(0x5a0cdc) value 0x5a0cdc is a pointer to something on > the Go heap. > > In reality this value is assigned by Windows and is actually the window > handle. > > Initially I was just going to force my win.HWnd to be a uintptr (as > effectively its a handle). However the cgo code knows its actually an opaque > pointer and thus treats it as a real pointer (unsafe.Pointer). So I think > forcing my code to use a uintptr won't help. Also it seems that general > guidelines are to use unsafe.Pointer if its a pointer (or appears to be).
I didn't try to fully understand this code, but this point seems problematic. From Go's perspective, a value is either a pointer or not. There can't be any waffling on that. If win.HWnd is a handle, not a memory address, then you must treat it as a uintptr. If it is a pointer--if you could reliably convert it to a pointer type via unsafe.Pointer and dereference it to get valid data--then you must treat it as a pointer. From Go's perspective there is no such thing as an opaque pointer or a value that appears to be a pointer. It's a pointer or it isn't, and type must correspond. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.