Assigning a function pointer with prototype skipped forward in Nim

I want to assign a Window procedure to the Window class structure:

var wndClass : WNDCLASS;

wndClass.lpszClassName = CLASSNAME;
wndClass.lpfnWndProc   = WndProc;
wndClass.hInstance     = hInstance;

      

I can't assign the WndProc yet because it hasn't been declared. When I use the forward declaration (described here ):

proc WndProc(hWnd: HWND; msg: WINUINT; wParam: WPARAM; lParam: LPARAM) : LRESULT

      

I am getting this error:

Error: type mismatch: got (None) but expected 'WNDPROC'

      

Is my direct declaration wrong or do I need to write a function first in this case?

Edit:

For reference, the following code works in the global scope:

proc Foo : int32;

var bar = Foo();
var baz = Foo;

echo bar;
echo baz();

proc Foo : int32 =
    return 4;

      

The definitions of WNDCLASS and WNDPROC can be found here: http://nim-lang.org/windows.html

+3


source to share


1 answer


The problem was that although the WNDPROC type definition includes pragmas, you must repeat them in forward declarations.

This code compiles:



import windows

proc WndProc(hWnd: HWND; msg: WINUINT; wParam: WPARAM; lParam: LPARAM) : LRESULT {.stdcall.}

var wndClass : WNDCLASS;
wndClass.lpfnWndProc   = WndProc;

proc WndProc(hWnd: HWND; msg: WINUINT; wParam: WPARAM; lParam: LPARAM) : LRESULT = 0

      

By the way, if you are trying to recreate the problem by including the types in the file, it fails due to case insensitivity.

+4


source







All Articles