Hello, All.
I have this code.
I need to pass a certain procedure (SetFocus) as parameter (LPVOID) to another procedure (pass).
But as it turned out there are a lot of SetFocus procs in winim module. I need only one of them. Question: how can I elegantly specify the one that i need (HWND SetFocus(HWND))
from winim as win import LPVOID
#from winim/inc/winuser as win import nil
proc pass(p: LPVOID) =
echo p.repr
#pass(win.MessageBoxA) # this works
pass(win.SetFocus) # this doesn't. type mismatch. because "SetFocus" symbol is ambiguous.
echo win.SetFocus.typeof # type = None
if i uncomment the second line, the code works, but i think it looks like workaround/hack.
pass((proc(hwnd: HWND): HWND)(win.SetFocus))
Error: ambiguous identifier: 'SetFocus'
Yes this is a case of HWND describing a lot if you want a specific proc you need to do something like
import winim
proc pass(p: LPVOID) =
echo p.repr
pass (proc(hWnd: HWND): HWND{.stdcall.})(SetFocus)
thanks, ElegantBeef!
Manual: "Type conversion can also be used to disambiguate overloaded routines" this is something i have missed while learning Nim.
this is my code now. looks fine!
type hwndSetFocus = proc(hWnd: HWND): HWND{.stdcall.}
pass (hwndSetFocus)(win.SetFocus)