Using delegate for WindowProc - possible ?

bls bizprac at orange.fr
Thu Dec 29 12:08:44 PST 2011


On 12/28/2011 03:45 PM, Tal wrote:
> Can I do something like this :
> ______________________________________________________________________
> extern (Windows) LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,
> LPARAM lParam) MyWinProcDelegate;
>
> this() {
> 	MyWinProcDelegate =&Events;
> }
>
> extern (Windows) LRESULT Events (HWND hWnd, UINT message, WPARAM wParam,
> LPARAM lParam) {
> 	MessageBoxA(null , "Success!!!" , null ,0);
> 	return DefWindowProcA(hWnd, message, wParam, lParam);
> }
> ______________________________________________________________________
>
> The Events() doesn't seem to fire... am I missing something ?

ok next try, this works for me.

import std.stdio;
import std.functional;

int main(string[] argv)
{
	

	extern(Windows)	int delegate( int i) dg;
	alias dg callback;

			
			callback = toDelegate(&test);

			writeln( callback( 1 ) );
			
			readln();


return 0;
}

extern(Windows) int test(int i) { return 41 +i;}

hth, bjoern


More information about the Digitalmars-d-learn mailing list