lakshman_ce
May 24th, 2002, 04:53 AM
Please find attached the source files with which I am facing the problem . I would appreciate your help in this regard.
Thanks,
Lakshman
Thanks,
Lakshman
|
Click to See Complete Forum and Search --> : VC6 to VC7 causes C2440 in ON_COMMAND lakshman_ce May 24th, 2002, 04:53 AM Please find attached the source files with which I am facing the problem . I would appreciate your help in this regard. Thanks, Lakshman NigelQ May 24th, 2002, 08:30 PM Hi Lakshman, It sounds like the problem is in your code, not the compiler. One of the noticable changes made during the transition from version 6 to 7 was the tightening of the type checking all over the place. Once of these changes highlights previously overlooked problems in the message mapping and handling mechanism. Essentially what it is telling you is that your function prototypes for your message handlers are wrong. For example, an ON_MESSAGE handler should have this signature: afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); where previously, version 6 would not have complained if you told it the handler looked like this instead (for example): afx_msg void OnMyMessage(WPARAM wParam); This incorrect assignment of handlers leads to many more mysterious problems with applications than people realize - typically these problems are only apparent in release builds, rarely in debug builds!! You should also be aware that message handlers for different message types have different signatures both in terms of parameters and return types. Rather than frustrating you, it should bring you comfort that this additional checking is now being done (unfortunately this doesn't remove the need to rework your code). Hope this helps, - Nigel lakshman_ce May 24th, 2002, 10:40 PM Hi Nigel, Thanks for the reply. I would like to know more about ON_COMMAND message handler since that is root cause for my problems. I have around 15 errors reported becauze of this. MSDN tells that whenever we do ON_COMMAND message mapping, we should have the prototype as, afx_msg void OnMyCommand() In some of my source files, this function is returning BOOL instead of void. All this function message mappings gives error at compile time. If I am changing the return type to void, it compiles but by code won't work. The calling function of this command handler expects return value. As the prototype also says there should not be any parameter , I really wonder how I am going to pass a OUT parameter to the ON_COMMAND message handlers. The sample that I have attached over the zip is a very small module of my application. There are n number of modules like this and with all I have the same problem. I am afraid whether I would be able to make my code work the same way as it worked with VC6. I would be grateful to you if you advise me in this regard. Also I would like to you whether VC7 provides any option for making this work as it is. Thanks, Lakshman NigelQ May 25th, 2002, 02:09 PM Hi Lakshman, This is precisely the problem I described. You need to decide which type of message passing mechanism you need to use for your particular application (ON_COMMAND or ON_MESSAGE for example) then apply the necessary changes. You should also check out ON_COMMAND_EX which might be a little closer to your needs. I beleive there is no way to have VC7 to compile the code as is - it is being (correctly) detected as a compile error (you might be able to convince the compiler to disable this error detection, ... but then you're all on your own). Again, I'd point out that this kind of mismatch causes mysterous crashes - you might have seen some with your application ? Think about what this mismatching is doing to your stack - it's getting trashed as the handler exits. Hope this helps, - Nigel lakshman_ce May 26th, 2002, 10:33 PM Thanks Nigel. I have corrected my code accordingly. -Lakshman codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |