Can someone please assist me in understanding why i am receiving this
error: " error C2440: 'type cast' : cannot convert from 'LRESULT
(__cdecl CMyToday::* )(HWND,UINT,WPARAM,LPARAM)' to 'LONG' "
Here is the source snippet that is causing this compile error. The
error is caused by the SetWindowLong line below.
MyDataWin.h
WNDPROC _hOldWndProc;
BOOL Create( HWND hWndParent, DWORD dwStyle = WS_VISIBLE | WS_CHILD
);
LRESULT CALLBACK EditWinProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam );
MyDataWin.cpp
BOOL MyDataWin::Create( HWND hWndParent, DWORD dwStyle )
{
_hEditBox = CreateWindow( L"EDIT", NULL, WS_CHILD | WS_VISIBLE |
ES_AUTOHSCROLL, 2, 2, 100, 20, m_hWnd, NULL, _hInstance, NULL );
_hOldWndProc = SetWindowLong( _hEditBox ,GWL_WNDPROC, (LONG)
EditWinProc );
}
LRESULT CALLBACK MyDataWin::EditWinProc( HWND hWnd, UINT uMsg, WPARAM
wParam, LPARAM lParam )
{
....
....
} 8 2705
farseer wrote: Can someone please assist me in understanding why i am receiving this error: " error C2440: 'type cast' : cannot convert from 'LRESULT (__cdecl CMyToday::* )(HWND,UINT,WPARAM,LPARAM)' to 'LONG' "
And your C++ question is...?
Please have a look at http://www.parashift.com/c++-faq-lit...t.html#faq-5.9.
Jonathan
* farseer: Can someone please assist me in understanding why i am receiving this error: " error C2440: 'type cast' : cannot convert from 'LRESULT (__cdecl CMyToday::* )(HWND,UINT,WPARAM,LPARAM)' to 'LONG' "
First of all, see the FAQ item "How do I post a question about code that
doesn't work correctly?", currently at <url:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>.
Here is the source snippet that is causing this compile error. The error is caused by the SetWindowLong line below.
MyDataWin.h
WNDPROC _hOldWndProc; BOOL Create( HWND hWndParent, DWORD dwStyle = WS_VISIBLE | WS_CHILD ); LRESULT CALLBACK EditWinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
MyDataWin.cpp
BOOL MyDataWin::Create( HWND hWndParent, DWORD dwStyle ) {
_hEditBox = CreateWindow( L"EDIT", NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 2, 2, 100, 20, m_hWnd, NULL, _hInstance, NULL );
_hOldWndProc = SetWindowLong( _hEditBox ,GWL_WNDPROC, (LONG) EditWinProc ); }
LRESULT CALLBACK MyDataWin::EditWinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { ... ... }
You're using a compiler that allows two things that standard C++ does
not allow:
* Taking the address of a non-static member funtion implicitly.
* Specifying the machine code level calling convention of a member
function.
In short, you shouldn't be using a non-static member function, here your
'EditWinProc', as a C-style callback: a non-static member function must
be called on an object, and a C-style callback isn't.
Assuming a C-style callback is what you're trying to do.
Here are some additional tips:
Don't use prefix underscores in names.
Don't use C-style casts.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
farseer wrote: Can someone please assist me in understanding why i am receiving this error: " error C2440: 'type cast' : cannot convert from 'LRESULT (__cdecl CMyToday::* )(HWND,UINT,WPARAM,LPARAM)' to 'LONG' "
Here is the source snippet that is causing this compile error. The error is caused by the SetWindowLong line below.
MyDataWin.h
WNDPROC _hOldWndProc; BOOL Create( HWND hWndParent, DWORD dwStyle = WS_VISIBLE | WS_CHILD ); LRESULT CALLBACK EditWinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
MyDataWin.cpp
BOOL MyDataWin::Create( HWND hWndParent, DWORD dwStyle ) {
_hEditBox = CreateWindow( L"EDIT", NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 2, 2, 100, 20, m_hWnd, NULL, _hInstance, NULL );
_hOldWndProc = SetWindowLong( _hEditBox ,GWL_WNDPROC, (LONG) EditWinProc ); }
LRESULT CALLBACK MyDataWin::EditWinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { ... ... }
I think, your compiler is quite explicit about it: in the expression
(LONG) EditWinProc
you are trying to cast a function pointer to LONG -- whatever that maybe.
(Actually, since the code is riddled with non-standard macros, one cannot be
sure about this.) Anyway, such cast is not necessarily possible. The
standard only requires that casts from pointers to integral types are
defined when the integral type is large enough to hold the pointer. Also,
it is not entirely clear from the wording of the standard whether this
provision covers function pointers at all (although that would be a
straight forward interpretation).
Best
Kai-Uwe Bux
farseer wrote: Can someone please assist me in understanding why i am receiving this error:
How to read a compiler error:
" error C2440: 'type cast' :
Okay, it's an error related to typecasting. Also, there is an error
number, which you could look up in your compiler's documentation or
search for on the web.
Now, typecasting is conversion from one type to another. What types
are involved?
cannot convert from 'LRESULT (__cdecl CMyToday::* )(HWND,UINT,WPARAM,LPARAM)'
Okay, that's what we're trying to convert from. Kind of an ugly type
name, and non-standard, but basically this is a member function of the
class CMyToday, which takes four parameters and returns an LRESULT.
to 'LONG' "
And here's what you're trying to convert it to.
Here is the source snippet that is causing this compile error. The error is caused by the SetWindowLong line below.
_hOldWndProc = SetWindowLong( _hEditBox ,GWL_WNDPROC, (LONG) EditWinProc );
Yup, there it is. So, the conversion of EditWinProc to LONG is not
permitted (no such conversion exists, the compiler is telling us). Why
are you attempting it?
In the future, please read the FAQ ( http://parashift.com/c++-faq-lite)
before posting here, specifically the sections on how to post code and
what kinds of questions are on-topic. You should post code that
actually compiles, and take questions about platform-specific and/or
non-standard extensions to a more appropriate forum.
Luke
Thanks Alf. changing the callback to static resolved the compile issue
(though i am not sure why ye).
btw, where should one post if their code does not compile (since
everyone seems to have an issue with that).
"farseer" <fa*****@optonline.net> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com... Thanks Alf. changing the callback to static resolved the compile issue (though i am not sure why ye).
btw, where should one post if their code does not compile (since everyone seems to have an issue with that).
Actually, not everyone had a problem with it. I believe your question was a
legitamite C++ question as did the 3 other people who replied other than
Jonathan.
Jim Langston wrote: "farseer" <fa*****@optonline.net> wrote in message news:11**********************@j55g2000cwa.googlegr oups.com... Thanks Alf. changing the callback to static resolved the compile issue (though i am not sure why ye).
btw, where should one post if their code does not compile (since everyone seems to have an issue with that).
Actually, not everyone had a problem with it. I believe your question was a legitamite C++ question as did the 3 other people who replied other than Jonathan.
The question was indeed a "legitimate C++ question", but not a
"legitimate comp.lang.c++ question". The FAQ clearly states that
"[u]ltimately this means your question must be answerable by looking
into the C++ language definition as determined by the ISO/ANSI C++
Standard document, and by planned extensions and adjustments."
The OP referred specifically to the Win32 API; the question is about
calling a Win32 function with bad arguments; the code snippet uses a
plethora of non standard things and was not compilable (as per 5.8).
This question was not about a problem with standard C++, it was about a
problem with a proprietary API which the OP was unable to use
correctly. I therefore forwarded him to the FAQ, in which he probably
found the relevant newsgroup.
Jonathan
Jonathan Mcdougall wrote: This question was not about a problem with standard C++, it was about a problem with a proprietary API which the OP was unable to use correctly. I therefore forwarded him to the FAQ, in which he probably found the relevant newsgroup.
I disagree. His question was clearly about type conversion. The Win32
API was only an unhappy case study This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BJörn Lindqvist |
last post by:
A problem I have occured recently is that I want to subclass builtin
types. Especially subclassing list is very troublesome to me. But I
can't find the right syntax to use. Take for example this...
|
by: Brent |
last post by:
I'd like to subclass the built-in str type. For example:
--
class MyString(str):
def __init__(self, txt, data):
super(MyString,self).__init__(txt)
self.data = data
|
by: Massimiliano Alberti |
last post by:
Can I specialize a template function in a subclass without overriding
it? (the main template function is defined in a base class).
Now I'm doing something like that:
(in base class)...
|
by: Chuck Haeberle |
last post by:
We have need to share functionality across all of our application web pages, so we decided to subclass from System.Web.UI.Page. When we create a new aspx, the Visual Studio designer automatically...
|
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you...
|
by: Jan Callewaert |
last post by:
Hi,
since I want to specify an extra function for a std::valarray<float>, I want
to subclass it:
class FVector : public std::valarray<float> {
public:
FVector() : std::valarray<float>() {}...
|
by: manatlan |
last post by:
I've got an instance of a class, ex :
b=gtk.Button()
I'd like to add methods and attributes to my instance "b".
I know it's possible by hacking "b" with setattr() methods. But i'd
like to do...
|
by: Ray |
last post by:
Hi all,
I am thinking of subclassing the standard string class so I can do
something like:
mystring str;
....
str.toLower ();
A quick search on this newsgroup has found messages by others
|
by: =?Utf-8?B?QmV0aA==?= |
last post by:
Hello.
I'm trying to figure out how to create subclasses with properties specific
to the subclass and so far it isn't going well.
Right now I have a class with an enum representing the type. ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |