Solved

SetWindowLong

Posted on 2002-03-21
2
255 Views
Last Modified: 2008-02-01
Hellow experts...

In a cpp file almost the first line is this prototype.

LRESULT CALLBACK ShowPointWndProc(HWND, UINT, WPARAM, LPARAM);

Of course that function is defined at the bottom of the file.

The problem is this one.

In the InitDialog message (I am trying to subclass an item in the dialog) I am trying to:

WNDPROC OldAdd = SetWindowLong (hItemWnd, GWL_WNDPROC, (LONG)ShowPointWndProc);

This will never be compiled because the error is this.

DialogProcs.cpp(34) : error C2440: '=' : cannot convert from 'long' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'

I tried:

WNDPROC OldAdd = SetWindowLong (hItemWnd, GWL_WNDPROC, (LONG)&ShowPointWndProc);

WNDPROC OldAdd = SetWindowLong (hItemWnd, GWL_WNDPROC, (WNDPROC)&ShowPointWndProc);

But nothing works...

Please help me.

Thank you very much.





0
Comment
Question by:Marsc
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6885477
Make it read

WNDPROC OldAdd = (WNDPROC) SetWindowLong (hItemWnd, GWL_WNDPROC, (LONG)ShowPointWndProc);

'SetWindowLong()' returns a 'long', you'll have to typecast when storing it as a 'WNDPROC'...
0
 
LVL 1

Author Comment

by:Marsc
ID: 6886292
Problem solved :-)
Thank you very much...
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question