I want to migrate my application from VC++ 6.0 to MS Visual studio 2010.
I am thinking to compile my old code(VC++ 6.0) in Visual 2010 and resolve the compiler errors. Is it ok? Or I need to do any modification.
My application is having one exe and all other modules are dlls.
I believe that I need to compile exe as well as dlls in visual studio 2010.
Is it ok? Or I can only compile exe and dlls can be used as it is.
Because dlls are created in old VC++6.0.
If you have complex projects, they may need manual recreation because the conversion isn't always capable of picking up all the subtleties. It's good 99% of the time though.
You'll get lots and lots of warnings concerning Win64 compatibility, and the secure library functions.
Since V6 wasn't entirely standard C++, if you have extensive templates, this may need work.
If you are dependant on some of the weird oddities and quirks of V6, then thos will need rewriting and they'r elikely going to be your biggest problem, not all of them show up from compiling issues, a lot won't get noticed until you do actual testing.
The main issue we had when porting from VC6 to VS2005 was that counters defined in a for loop are no more valid after the loop. However the compiler will tell you all of these changes and if you simply define the loop variable above the loop you have a simple and straight forward solution to the issue.
Same applies if you used old iostream.h and now have to use <iostream> from STL (the iostream.h wasn't supported anymore). Then you need to add the std:: prefix to cout, cin, endl, ... or add the 'using namespace std;' to all cpp files.
Some of the runtime functions, e. g. strcpy are called deprecated in VS2010 (but still can be used afaik). You either go with the warnings, or suppress the warnings with a '#pragma warning' preprocessor statement or change to functions like strcpy_s which were offered as alternative. However, those functions are proprietary MS and the change may actually lead to a different program behavior or is at least error-prone.
If the VC6 project used STL you might experience more complex errors, especially regarding iterators where VC6 often used simple pointers while later versions have iterator objects.
A subtle compiler error is when you defined class variables in a way that can be interpreted as forward declarations of a function.
Code:
MyClass mc();
While the above compiles in VC6 all compilers since VC8 (VS2005) will take that as forward declaration of a function 'mc' which returns 'MyClass'. Hence all later statements using 'mc' will not compile.
i am facing the problem in the below code while pprting from VC++ 6.0 to VS 2010.
in VC++, the below code compiles properly
if (GetData()->nDataLength == 0)
return;
if (GetData()->nRefs >= 0)
{
// Release();
// Do not call Release. Instead Empty the string.
if (InterlockedDecrement(&GetData()->nRefs) <= 0)
{
m_pchData[0] = '\0';
GetData()->nDataLength = 0;
InterlockedIncrement(&GetData()->nRefs);
}
else
{
Init();
}
}
else
CString::Empty();
ASSERT(GetData()->nDataLength == 0);
ASSERT(GetData()->nRefs <= 1 || GetData()->nAllocLength == 0);
#endif
But in VS 2010 i was facing the below error.
t:\sharedcr\source\gpsstr.cpp(262): error C2248: 'ATL::CSimpleStringT<BaseType,t_bMFCDLL>::GetData' : cannot access private member declared in class 'ATL::CSimpleStringT<BaseType,t_bMFCDLL>'
1> with
1> [
1> BaseType=char,
1> t_bMFCDLL=true
1> ]
I got some answer from google the i modified GetData()->nDataLength into ((CString*)this)->GetBuffer(). It is not giving any error. But when I try to modify
InterlockedIncrement(&GetData()->nRefs); into
InterlockedIncrement(&((CString*)this)->GetBuffer());
getting error like
1> t:\sharedcr\source\gpsstr.cpp(262): error C2102: '&' requires l-value
pls see the below code and guide what should be done.
#else
// 32 bit code RAJ01
if (((CString*)this)->GetBuffer() == 0)
return;
if (((CString*)this)->GetBuffer() >= 0)
{
// Release();
// Do not call Release. Instead Empty the string.
if (InterlockedDecrement(&((CString*)this)->GetBuffer()) <= 0)
{
CString::GetBuffer()[0] = '\0';
((CString*)this)->GetBuffer()[0] = 0;
InterlockedIncrement(&((CString*)this)->GetBuffer());
}
else
{
AfxOleInit();
}
}
else
CString::Empty();
ASSERT(((CString*)this)->GetBuffer() == 0);
ASSERT(((CString*)this)->GetBuffer()[0] <= 1 || ((CString*)this)->GetBuffer() == 0);
#endif
1. Your code is very hard to read/understand. The reason is you didn't use Code tags. Please, read Announcement: Before you post.... and try to edit your post adding code tags.
2. What is the code you have posted supposed to do? It looks like Microsoft source code from CString implementation. Doesn't it?
Note that in VC++ versions after VC++6.0 the CString class was completely overwritten, so "the old 6.0" things might not work at all.
i am facing the problem in the below code while pprting from VC++ 6.0 to VS 2010.
What exactly are you trying to do with a CString that requires calls to InterlockedIncrement and InterlockedDecrement? Is that your code?
A CStrng is something simple -- a class that wraps an array of characters. You are supposed to use the public interface of CString, and not assume how the internals are to work. If you did that, then you would have no problems with going from Visual C++ 6.0 to VS 2010.
The only issue is if you tried to mix modules compiled with VC 6.0 with modules compiled with VS 2010. Since CString is different in both versions, then you cannot pass CString objects between these modules.
I am attaching the file. Pls have a look and guid me.
Rani
So where is the code that uses CString? I don't see any CString objects in any of the code you have.
All I see are calls to internal CString functions or functions that mimic what CString does internally, which means that whoever coded this had either copied the CString class and tried to make their own CString, or they derived from CString, and started to mess around with CString internals.
Did you derive from CString, so that you can get at the internals of CString? If you did do this, that is very naive on your part, and no one can help you. A class such as CString is meant to be used properly, meaning you use only the functions from the public interface. Once you start fooling around with the internals of classes you didn't write, then you are stuck if that class happens to change in another version.
The CString class in Visual C++ 6.0 is non-templated, while the one in VS 2010 is now a template class. As I stated previously, if you used CString as it was intended to be used, you would have no problems going from VC 6.0 to VS 2010.
And again, what are you trying to do with that code? Create a thread-safe CString? If so, why? If indeed you are trying to make a class thread safe, the way to do that is not to go into the internals of the class. You restrict access to the CString using synchronization objects (critical section, mutex, etc.).
Regards,
Paul McKenzie
Last edited by Paul McKenzie; March 25th, 2011 at 06:13 PM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.