View previous topic :: View next topic |
Author |
Message |
Abscissa
Joined: 23 Feb 2005 Posts: 40 Location: Cleveland, OH, US
|
Posted: Sun Feb 19, 2006 12:35 am Post subject: How to use callbacks? |
|
|
I'm having trouble using a callback:
callback.d:
Code: | import win32.api;
extern(Windows) BOOL EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
} // line 6
int main(char[][] args)
{
EnumWindows(&EnumWindowsProc, 0);
return 0;
} |
That compiles fine, but when I run it I get:
Code: | Error: AssertError Failure callback(6) |
|
|
Back to top |
|
|
AgentOrange
Joined: 21 Jul 2005 Posts: 61
|
Posted: Sun Feb 19, 2006 12:48 am Post subject: |
|
|
the callback needs to return a bool. |
|
Back to top |
|
|
Abscissa
Joined: 23 Feb 2005 Posts: 40 Location: Cleveland, OH, US
|
Posted: Sun Feb 19, 2006 12:53 am Post subject: |
|
|
LOL, nevermind, I'm an idiot
Code: | import win32.api;
extern(Windows) BOOL EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
[b]return TRUE;[/b]
}
int main(char[][] args)
{
EnumWindows(&EnumWindowsProc, 0);
return 0;
} |
|
|
Back to top |
|
|
Abscissa
Joined: 23 Feb 2005 Posts: 40 Location: Cleveland, OH, US
|
Posted: Sun Feb 19, 2006 12:54 am Post subject: |
|
|
Although I have to say, I'm really surprised the compiler didn't catch that. |
|
Back to top |
|
|
AgentOrange
Joined: 21 Jul 2005 Posts: 61
|
Posted: Sun Feb 19, 2006 2:55 am Post subject: |
|
|
Abscissa wrote: | Although I have to say, I'm really surprised the compiler didn't catch that. |
Welcome to D
I believe this is because walter allows you to have paths that do not return a value - as long as its never called. Why - who knows. Therefore he just asserts at runtime. And yes, just about everyone but walter wants it to at least say "YOU FORGOT TO RETURN". Its just one of those things you remember after a while... |
|
Back to top |
|
|
|