Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 28, 2011 Using delegate for WindowProc - possible ? | ||||
---|---|---|---|---|
| ||||
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 ? |
December 29, 2011 Re: Using delegate for WindowProc - possible ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tal | On Wednesday, 28 December 2011 at 23:45:05 UTC, 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 ?
Nope. You are trying to assign the address of a function to a delegate, both are differents.
|
December 29, 2011 Re: Using delegate for WindowProc - possible ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tal | 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
|
December 29, 2011 Re: Using delegate for WindowProc - Is possible and fun! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tal | 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 ? Hi Tal. I have added an other example using array of delegates. I guess I know what you want to do... so do not miss the end of the document. Enjoy. import std.stdio; import std.functional; int main(string[] argv) { // array of delegates extern(Windows) int delegate( int i)[] dg; alias dg callback; // function to delegate callback ~= toDelegate( &test ); // std.functional writeln( callback[0]( 1 ) ); callback ~= toDelegate( &inc ); writeln( callback[1] (0) ); writeln (callback[0]( 1 ) ); readln(); return 0; } extern(Windows) int test(int i) { return 41 +i;} extern(Windows) int inc(int i) { return ++i;} ------------------------------------------------------------------------------------ // Now an associative array of delegates indexed by (of course) HWND ;) extern (Windows) LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,LPARAM lParam)[HWND] dg; alias dg MyWinProcDelegate; bjoern |
December 30, 2011 Re: Using delegate for WindowProc - possible ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bls | On Thursday, 29 December 2011 at 20:08:45 UTC, bls wrote:
> 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
Wow! This is actually pretty cool! I needed something similar, but it was to call a member function from the Windows procedure, and I had to use some thunking though assembly.
Maybe I can adapt my code to use a delegate like this instead.
|
Copyright © 1999-2021 by the D Language Foundation