How to register class member function as lpfnWndProc? Cannot convert delegate to function

Maxim Fomin maxim at maxim-fomin.ru
Fri Sep 28 12:35:04 PDT 2012


On Friday, 28 September 2012 at 17:53:59 UTC, deed wrote:
> Hi
>
> I am trying to register a class member function as 
> wc.lpfnWndProc, but get the error message "cannot implicitly 
> convert expression (&this.WndProc) of type extern (Windows) int 
> delegate(...) to extern (Windows) int function(...).
>
> I have:
>
> extern (Windows)
> class App
> {
>     HRESULT initialize(HINSTANCE hInstance, int iCmdShow)
>     {
>         WNDCLASS wc;
>         ...
>         wc.lpfnWndProc = &wndProc;
>         ...
>     }
>
>     HRESULT wndProc(HWND hwnd, UINT message, WPARAM wParam, 
> LPARAM lParam)
>     {
>         switch (message)
>         {
>             ...
>         }
>     }
>     ...
> }
>
>
> (Defining wndProc as a global function works, but is not what I 
> want to do...)
> What is the issue here and how do I make it work?

Because wndProc in your case cannot be converted to a delegate. 
You can make it a module-level function (there is no globals in 
D) or try to make it static function - I currently cannot check 
whether it works. In any way, what gives you making wndProc a 
class member function?


More information about the Digitalmars-d-learn mailing list