title: Lambda as WNDPROC C++
body: <p>I want to use c++ lambda expression as a window procedure in WinApi.<br>
  I've seen it on many pages, <a href="https://kennykerr.ca/2014/03/29/classy-windows-2/" rel="nofollow noreferrer">this one for example</a>.<br>
  The code won't compile tho:</p>
  
  <pre><code>WNDPROC x = [](HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -&gt; LRESULT {
      return 0;
  };
  </code></pre>
  
  <p>Error I'm getting:  </p>
  
  <p><code>invalid user-defined conversion from 'main()::&lt;lambda(HWND, UINT, WPARAM, LPARAM)&gt;' to 'WNDPROC {aka long int (__attribute__((__stdcall__)) *)(HWND__*, unsigned int, unsigned int, long int)}' [-fpermissive]|</code></p>
  
  <p>The problem seems to lay in __stdcall convention, but when I'm trying to add it:</p>
  
  <pre><code>WNDPROC x = [](HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -&gt; CALLBACK LRESULT {
      return 0;
  };
  </code></pre>
  
  <p>The complier says:</p>
  
  <blockquote>
    <p>warning: '<strong>stdcall</strong>' attribute only applies to function types [-Wattributes]|</p>
  </blockquote>
  
  <p>So how are people using lambda as wndproc then?<br>
  Is it a compiler thing? (Does not work in CodeBlocks standard compiler, nor Visual Studio 2015)</p>