Migration from VC2006 to 2008
-
HI. I have been using 2006 and have not upgraded through the years. All works. Now, I installed VC2008 and find that the old code has many compiler errors. I am not sure where these come from. One is ex: for (int x = 0; x< 100;x++) .... for (x = 0; x<5;x++).... THis will nor work anymore... It seems I need to declare the X outside the for loop. The other is : Error 2440: 'static cast' cannot convert from 'void (thiscall CMyView::*)(WPARAM, LPARAM)' to '(LRESULT (thiscall CWnd::*)(WPARAM, LPARAM)' Not sure what this one is. Never had any of these problems before. Also, just curious if maybe I should just go to 2011 version versus 2008? Any comments? Appreciate any help or advise. Thanks. Stan the man
-
HI. I have been using 2006 and have not upgraded through the years. All works. Now, I installed VC2008 and find that the old code has many compiler errors. I am not sure where these come from. One is ex: for (int x = 0; x< 100;x++) .... for (x = 0; x<5;x++).... THis will nor work anymore... It seems I need to declare the X outside the for loop. The other is : Error 2440: 'static cast' cannot convert from 'void (thiscall CMyView::*)(WPARAM, LPARAM)' to '(LRESULT (thiscall CWnd::*)(WPARAM, LPARAM)' Not sure what this one is. Never had any of these problems before. Also, just curious if maybe I should just go to 2011 version versus 2008? Any comments? Appreciate any help or advise. Thanks. Stan the man
In your first statement above you declare
x
to be an integer, however it only exists within thefor
block, so (I assume, since you did not show all your code) when you get to the second statement,x
is unknown. The C2440 message is described here[^].One of these days I'm going to think of a really clever signature.
-
In your first statement above you declare
x
to be an integer, however it only exists within thefor
block, so (I assume, since you did not show all your code) when you get to the second statement,x
is unknown. The C2440 message is described here[^].One of these days I'm going to think of a really clever signature.
The problem is that it works in the old code. The declaration for x is valid through the function that the second for is in. So it never was a problem before.
-
The problem is that it works in the old code. The declaration for x is valid through the function that the second for is in. So it never was a problem before.
-
HI. I have been using 2006 and have not upgraded through the years. All works. Now, I installed VC2008 and find that the old code has many compiler errors. I am not sure where these come from. One is ex: for (int x = 0; x< 100;x++) .... for (x = 0; x<5;x++).... THis will nor work anymore... It seems I need to declare the X outside the for loop. The other is : Error 2440: 'static cast' cannot convert from 'void (thiscall CMyView::*)(WPARAM, LPARAM)' to '(LRESULT (thiscall CWnd::*)(WPARAM, LPARAM)' Not sure what this one is. Never had any of these problems before. Also, just curious if maybe I should just go to 2011 version versus 2008? Any comments? Appreciate any help or advise. Thanks. Stan the man
Stan the man wrote:
for (int x = 0; x< 100;x++)
....
for (x = 0; x<5;x++)....THis will nor work anymore... It seems I need to declare the X outside the for loop.
This because the
VC
compiler was not compliant with theC++
standard. See this page[^] for a reason why. That eventually changed andVC
is now compliant.Stan the man wrote:
Error 2440: 'static cast' cannot convert from 'void (thiscall CMyView::*)(WPARAM, LPARAM)' to '(LRESULT (thiscall CWnd::*)(WPARAM, LPARAM)'
Not sure what this one is. Never had any of these problems before.This is a change in the Microsoft's
MFC
library (see for instance here[^]).Veni, vidi, vici.
-
Stan the man wrote:
for (int x = 0; x< 100;x++)
....
for (x = 0; x<5;x++)....THis will nor work anymore... It seems I need to declare the X outside the for loop.
This because the
VC
compiler was not compliant with theC++
standard. See this page[^] for a reason why. That eventually changed andVC
is now compliant.Stan the man wrote:
Error 2440: 'static cast' cannot convert from 'void (thiscall CMyView::*)(WPARAM, LPARAM)' to '(LRESULT (thiscall CWnd::*)(WPARAM, LPARAM)'
Not sure what this one is. Never had any of these problems before.This is a change in the Microsoft's
MFC
library (see for instance here[^]).Veni, vidi, vici.
Thank everyone for their input. Will go through and properly get everything done. Appreciate the help.
-
Thank everyone for their input. Will go through and properly get everything done. Appreciate the help.
-
HI. I have been using 2006 and have not upgraded through the years. All works. Now, I installed VC2008 and find that the old code has many compiler errors. I am not sure where these come from. One is ex: for (int x = 0; x< 100;x++) .... for (x = 0; x<5;x++).... THis will nor work anymore... It seems I need to declare the X outside the for loop. The other is : Error 2440: 'static cast' cannot convert from 'void (thiscall CMyView::*)(WPARAM, LPARAM)' to '(LRESULT (thiscall CWnd::*)(WPARAM, LPARAM)' Not sure what this one is. Never had any of these problems before. Also, just curious if maybe I should just go to 2011 version versus 2008? Any comments? Appreciate any help or advise. Thanks. Stan the man
Stan the man wrote:
I have been using 2006
Just for my own sanity you are actually referring to VC6 right? There is no such thing as "VC2006" and the compilers around 2006 such as Visual Studio 2005 were compliant. But Visual Studio C++ 6, known as VC6, was released in 1998 and was not compliant.
-
The problem is that it works in the old code. The declaration for x is valid through the function that the second for is in. So it never was a problem before.
It was not a problem before, because the compiler did things that were not standard. But starting with Visual Studio 2005, the scope of the variables does not exceed the block they are defined in. And that applies to for loops too. So you either declare the index variable before the first for loop, or re-declare it in each for statement. As for the other problem, it's also an error with the old compiler. Your actual handler should return LRESULT, not void. So change the function to the requested signature (take a WPARAM and LPARAM and return LRESULT) and everything will be OK. BTW, there is no such thing as VS2006. There is VS2002, VS2003, VS2005 and VS2008.