"error C2228: left of '.ToString' must have class/struct/union" - visual-studio-2012

So I recently got Visual Studio 2012. I converted a Visual Studio 2010 solution to a Visual Studio 2012 project. It was working before I converted it.
I have this line of code:
this->Text = global::ProjectName + " (" + global::Type.ToString() + ") - Path Creator 2.0";
where global::Type is:
ref class global {
public:
static Rct3PathType Type;
...
};
...and Rct3PathType is:
enum class Rct3PathType {
Basic = 0x02060206,
Extended = 0x05060506,
Queue = 0x01070107
};
I get an error at compile time where ever I have called global::Type.ToString() saying "error C2228: left of '.ToString' must have class/struct/union". Considering this all compiled completely well BEFORE switching to Visual Studio 2012, I'm not sure what the issue is! :(
Also, when I try to run the last successful build (which was built with Visual Studio 2010), I get runtime error at startup saying "The program can't start becayse MSVCR100D.dll is missing from your computer." I know this probably doesn't relate to the issue at hand, but does anyone know why this may be happening as well?
Thanks for your help,
Alex

"error C2228: left of '.ToString' must have class/struct/union": enum class is also the syntax for a C++11 enum. To make it a C++/CLI enum, give it an accessibility specifier, which is not allowed on a C++11 enum. In other words, private enum class or public enum class will change it from a C++11 enum to a C++/CLI enum. This wasn't a problem in VS2010 because it doesn't support C++11 enums.
"The program can't start because MSVCR100D.dll is missing from your computer.": VS2012 uses a different C runtime than VS2010. MSVCR100D is the Microsoft Visual C Runtime version 10.0, Debug version. This DLL is installed with VS2010, there is no other way to get it. If you have an old Release build, you can get the runtime redistributable from Microsoft (x86 or x64), and install that to make it run. (That will be MSVCR100.dll, no "D" at the end.)

Related

visual c++ 6.0 - rebuild all throw error C2259

The project was created using Visual C++ 6.0 and I'm new to using Visual C++. Now in my project, I set up Visual C++ on Windows 10, but when rebuild all below error C2259 throw. Please help me how to fix this error C2259. Thanks in advance.
D:\VS98\VC98\ATL\INCLUDE\atlcom.h(1827) : error C2259: 'CComObject' : cannot instantiate abstract class due to following members:
D:\VS98\VC98\ATL\INCLUDE\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator<class ATL::CComObject >::CreateInstance(void *,const struct _GUID &,void ** )'
At last, found the issue. One of the method definitions is different.
To resolve,
Check the function declarations and definitions prototypes in the .cpp,.h and .idl files. Also, check if they are same in all the 3 files.
.idl file we usually miss out on modifying since the search result doesn't show the method.

Using 'auto' in for each causes C3539 - Why?

I am writing a managed DLL in VC2010 (i.e. /CLR is enabled for a VC++ DLL project). Following code wouldn't compile:
System::Collections::Generic::List<int>^ my_list;
for each(auto elem in my_list)
{
}
It raises error C3539: 'auto': a template-argument cannot be a type that contains 'auto'.
I don't understand the reason. I tried compiling the same in VS2012, and it raises same error (which is not appropriate error).
Why compiler fails to deduce the type for a colleciton? The same type of code would work in C# with var keyword.
First, the most importand point from the comments:
presented code does compile in VS2013 c++/cli dll .net 4.5 (Zee, 2014-05-03)
When you compile C++/CLI, which is the .NET binding for C++, you are using a different feature set of the Microsoft compiler. Whether something works either
when /clr is in effect
or, additionally, when you're using a "managed" construct (as in your code)
has nothing to to with if the "normal", native, MSVC compiler accepts it.
So as for "why": It would simply appear that auto type deduction did not work for the managed handle types in VS2010 and VS2012, but, according to Zee's comment, has then been implemented in VS2013. (A quick Search Engine check didn't find any official statement wrt. this, so I may be wrong.)

Visual C++ Release build - is string getting corrupted when passed across DLL because compiled with different runtime version?

After building in Release mode, I am seeing exceptions which didn't occur in Debug mode. When debugging the release build, it looks like string references are not being passed correctly from the EXE (our application) to the DLL which is receiving the string reference.
Our EXE code looks like this:
string contents = "handle_message(): received=" + msg->encode();
LOG4CXX_DEBUG(logger, contents);
The LOG4CXX_DEBUG is going to log4cxx.dll, whose code looks like this:
CharMessageBuffer& CharMessageBuffer::operator<<(const std::basic_string<char>& msg) {
if (stream == 0) {
buf.append(msg);
} else {
*stream << msg;
}
return *this;
}
Looking at the Call Stack in the debugger, when I navigate down to the frame which has our source, I can see that contents is a valid string with size=583, capacity=838.
In the frame inside the log4cxx.dll (the next frame above in the stack) the string reference shows size=838, capacity=363113231 (and the values are all garbage).
Both our app and log4cxx.dll were compiled on the same machine, using the same runtime settings (/MD), but different versions of Visual Studio. The log4cxx dll was compiled using Visual Studio 2008 and our application was compiled using Visual Studio 2010. Running dumpbin on the 2 objects shows:
Our App (EXE)
MSVCP100.dll
MSVCR100.dll
log4cxx.dll (DLL)
MSVCP90.dll
MSVCR90.dll
Is this problem due to the fact that they are using different runtime versions?
If you pass non-POD (plain old datatypes) between DLL/EXE boundaries (like STL string or CRT FILE pointers) you must use the same shared CRT.
In your case, you must recompile all DLLs/LIBs with the same compiler!
See also: I can pass std::string for a Dll and what i can do with DLL´s?
The implicit question is:"Is there a way to pass data, hopefully using string and other STL containers, to DLLs of another version of visual studio either previous or later than the one that I'm using?".
Aside from using POD, there are probably three approaches: shared memory, sockets( to local host ) and MSMQ. All of these methods require additional extensive programming, but the deeper answer is found in how the interface is changing the input parameter.
I have found a possible solution to the string passing problem on the internet. It removes one layer of corruption; cast a pointer to the container to a uint and pass the uint. Dereference the uint to the pointer and the object is revealed. Beware, auto_ptrs are usually deleted in this process, so don't use them. If the passed object is still offset incorrectly( this happened to me with VS08 passing to a VS13 ), then pass the c_str() of the string instead. It's certainly inelegant, but we need to know all the alternatives. See "HowTo: Export C++ classes from a DLL" in Code Project( Nov 22, 2012 ).

Initialize Objects by Using an Object Initializer

When I try to compile using Visual Studio 2005 Express Edition the example below that I extracted from http://msdn.microsoft.com/en-us/library/vstudio/bb397680.aspx, VS throws out 9 errors:
1) 6 errors are about the 6 gets/sets "must declare a body because it is not marked abstract or extern", and
2) 3 errors are about the { and } after the new StudentName, i.e. A new expression requires () or [] after type.
Please help. Thank you.
The sample there requires a newer compiler, it uses features not available with the compiler used by VS 2005. That document is part of the VS 2008 documentation, so VS 2008 or newer should be able to compile it.

fatal error C1001: An internal error has occurred in the compiler

While compiling on x64 plattform I am getting following error:
c:\codavs05\hpsw-sc\ovpacc\tools\codaaccesstest\coda_access.cpp(1572): fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\sizeopt.c', line 55)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
------ Build started: Project: asyncexample, Configuration: Release Win32 ------
If I change settings to preprocessor file (Yes) i am not getting any error.
About my environment: Upgrading Microsoft Visual Studio 2005 to 2010
Please help.
I have had this problem with VS2015 while building locally in Windows.
In order to solve it, I deleted my build folder (Output Directory as seen in Properties/General) and rebuilt the project.
This always seems to help when strange things happen during the build.
I’ve encountered this error many times in VC++. Do the following steps. They’ve sometimes helped me with this issue:
Take a look at the exact location, pointed out by compiler error.
Find any external types or classes used there at that location.
Change the order of “include path” of those files found in step 2 and rebuild the solution.
I hope that help !!!!
I am getting same error with VC2012. Setting up the project properties Optimization to Disabled (/Od) resolved the issue.
In my solution, i've removed output dll file of the project, and I've made project rebuild.
I encountered the same error and spent quite a bit of time hunting for the problem. Finally I discovered that function that the error was pointing to had an infinite while loop. Fixed that and the error went away.
In my case was the use of a static lambda function with a QStringList argument. If I commented the regions where the QStringList was used the file compiled, otherwise the compiler reported the C1001 error. Changing the lambda function to non-static solved the problem (obviously other options could have been to use a global function within an anonymous namespace or a static private method of the class).
I got this error using boost library with VS2017. Cleaning the solution and rebuilding it, solved the problem.
I also had this problem while upgrading from VS2008 to VS2010.
To fix, I have to install a VS2008 patch (KB976656).
Maybe there is a similar patch for VS2005 ?
I got the same error, but with a different file referenced in the error message, on a VS 2015 / x64 / Win7 build. In my case the file was main.cpp. Fixing it for me was as easy as doing a rebuild all (and finding something else to do while the million plus lines of code got processed).
Update: it turns out the root cause is my hard drive is failing. After other symptoms prompted me to run chkdsk, I discovered that most of the bad sectors that were replaced were in .obj, .pdb, and other compiler-generated files.
I got this one with code during refactoring with a lack of care (and with templates, it case that was what made an ICE rather than a normal compile time error)
Simplified code:
void myFunction() {
using std::is_same_v;
for (auto i ...) {
myOtherFunction(..., i);
}
}
void myOtherFunction(..., size_t idx) {
// no statement using std::is_same_v;
if constexpr (is_same_v<T, char>) {
...
}
}
I had this error when I was compiling to a x64 target.
Changing to x86 let me compile the program.
Sometimes helps reordering the code. I had once this error in Visual Studio 2013 and this was only solved by reordering the members of the class (I had an enum member, few strings members and some more enum members of the same enum class. It only compiled after I've put the enum members first).
In my case, this was causing the problem:
std::count_if(data.cbegin(), data.cend(), [](const auto& el) { return el.t == t; });
Changing auto to the explicit type fixed the problem.
Had similar problem with Visual Studio 2017 after switching to C++17:
boost/mpl/aux_/preprocessed/plain/full_lambda.hpp(203): fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1518)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
Solved by using Visual Studio 2019.
I first encountered this problem when i was trying to allocate memory to a char* using new char['size']{'text'}, but removing the braces and the text between them solved my problem (just new char['size'];)
Another fix on Windows 10 if you have WSL installed is to disable LxssManager service and reboot the PC.

Resources