|
-
Oct 21st, 2001, 10:09 PM
#1
Thread Starter
Lively Member
Function Pointers
PHP Code:
void (*Function(HWND hwnd);
How would I call that?
I'm trying to do like WNDCLASSEX does..... :-\ no luck....
if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
{
SetWindowText(hwnd,"I suck.");
SendMessage(hwnd,WM_START_SUCKING,0,0);
SendMessage(hwnd,WM_CRASH,0,0);
}
-
Oct 22nd, 2001, 05:11 AM
#2
transcendental analytic
should be
void (*Function)(HWND hwnd);
and you call it like
Function(somehwnd);
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 22nd, 2001, 01:56 PM
#3
Thread Starter
Lively Member
Heres my code: (Its an imitation MFC thing)
I excluded all the irrelevant parts
PHP Code:
class Window
{
public:
void (*OnDestroy)(HWND hwnd);
};
PHP Code:
LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
Window::OnDestroy(hwnd);
//ERROR OCCURS HERE
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return(0);
}
NOTE! THAT IS NOT IN THE CLASS!!!!
PHP Code:
void Cls_OnDestroy(HWND hwnd)
{
PostQuitMessage(0);
}
PHP Code:
w.OnDestroy=Cls_OnDestroy;
Error: C2064: term does not evaluate to a function
Any ideas?
if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
{
SetWindowText(hwnd,"I suck.");
SendMessage(hwnd,WM_START_SUCKING,0,0);
SendMessage(hwnd,WM_CRASH,0,0);
}
-
Oct 22nd, 2001, 06:47 PM
#4
transcendental analytic
call it like:
w.OnDestroy(hwnd);
or change OnDestroy to static
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 22nd, 2001, 07:18 PM
#5
Frenzied Member
Reason for the error:
Your 'OnDestroy' function pointer is a member variable of each instance of your class. It only has meaning in the context of an object which is an instance of your class; it doesn't mean anything when it's just associated with the class itself, not an instance of that class.
You have used the scope resolution operator, ::, to resolve the scope of your function pointer (ie to acquire the function pointer so you can call it). However, this will only give you access to static class members, since non-static class members have no meaning without an associated instance of that class.
As Kedaman suggests, the solutions are to either make the function pointer static (the same variable is available to all instances of a class) and continuing to use the scope resolution operator, ::, as you do at the moment, or alternatively to instantiate an object of the class and assign the function pointer in that object. You can then use that object to get to your member function pointer, and you can call it using the direct member access operator (the dot . ).
Looks like you want to do it the latter way, by using the dot instead of ::
Harry.
"From one thing, know ten thousand things."
-
Oct 22nd, 2001, 08:53 PM
#6
Thread Starter
Lively Member
Ahhh! I get it now!!!!
Thanks!
Now I remember that from my certification course thingy (not finished yet)
if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
{
SetWindowText(hwnd,"I suck.");
SendMessage(hwnd,WM_START_SUCKING,0,0);
SendMessage(hwnd,WM_CRASH,0,0);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|