Project compiles in only in a certain version of Visual Studio - c++

I have a project that uses MFC and standard C++. I dont know in which VS it was originally made. When opened on the machine with only VS2012 installed and on the machine with only VS2010 installed - it doesn't build, showing errors, mostly regarding type mismatch. For example:
CListBox &ltbx
CString s;
ltbx.AddString(s);
This shows error, saying that AddString doesn't take argument of a type CString. The same goes for
CListBox &ltbx
std::string str;
ltbx.AddString(str.c_str());
This code as well shows an error:
string str;
CString CInputID;
str = static_cast<string> (CInputID);
It says that there is no user defined conversion from CString to std::string.
No doubt, I should be using different types for strings and all, but the exact same project opened on the machine which has installed both VS2010 and VS2008 works just fine, all types are matched. So my question is how does this work? I am thinking, maybe VS2008 has some libraries that define all necessary conversions and VS2010 is just making use of them. If so, what are those libraries and how can i make this project work on machines with no 2008 studio installed?

AddString takes a LPCTSTR which is a const char* or const wchar_t* depending on whether _UNICODE is defined.
The difference is probably that _UNICODE is defined in your VS2012 project.

Related

(Presumable) false error in Android Studio, but compiler and app run fine

I have tried what most similar questions about false positives say: delete either the .idea/ folder (even ~/.gradle), exit project, reload, invalidate cache & restart, etc. I've also ran refresh c++ linked libraries just in case.
Now just a background: my entire project is fine in regards to the IDE lint checker. All files show proper warnings, etc. Except for this one singular line in my c++ side. (I'll show the whole method for context). I can build and run my project just fine, and when I even invoke this logic portion of the app, it behaves as expected, with no problems.
// Header (relevant member variable)
class MyClass {
private:
std::vector<std::vector<int>> mArrayOfFooBars
}
// MyClass.cpp
void MyClass::updateModel(int index, const std::vector<int>& fooBars) {
this->mArrayOfFooBars[index].assign(fooBars.begin(), fooBars.end());
doMoreCalculations();
}
In Android Studio foobars.begin() and fooBars.end() are maked with the following errors:
Parameter type mismatch: Types 'const int' and 'std::vector>::const_iterator' are not compatible
Parameter type mismatch: Types 'unsigned int' and 'const int' and 'std::vector>::const_iterator' are not compatible
This brings me to believe that perhaps there is an error with the linter, or maybe I have some compiler settings wrong and this should in fact be a compiler error. Either way, I'll try to provide as many settings as I feel are relavent, hopefully somebody can provide some useful suggestions.
Gradle Plugin Ver: 3.6.3 (recent)
Gradle Version: 5.6.4
SDK ver: 29
Build Tools Ver: 29.0.3
NDK (Side by side) - Not installed (Not really sure what this is)
CMake: 3.10.2 & 3.6.4111459 installed (probably only need one of these?)
SDK Platform-Tools (update available for 30.0.0)
SDK Tools: 26.1.1
I checked my linter settings (inspections) and didn't find any error level inspections for this:
And that's all I can think of, I'll just continue developing as normal, but it bothers me that it's there. So any help in eliminating this rogue error will be appreciated!
Errors in the IDE that doesn't show up as part of the build aren't unusual in Android Studio. The build and the IDE do not use the same toolchain. Old versions of Studio use CLion's C++ parser, which was often wrong because parsing C++ is notoriously difficult. New versions are starting to use clangd but it's not necessarily the same version of Clang as the build is using.
When you see issues like this odds are it'll be better in a newer version of AS, but it's often worth filing a bug to make sure it's on someone's radar.

Porting from Visual Studio Application to Qt Application

I have one project whose .SLN file is there and we are able to run the project on Visual Studio 2008 and In which we have qt extension added that we are using In our project.
I have tried to create .pro and pri using following link:
Converting .Sln Project to .pro Project
I have able see related lib and manage to add required file. But the Code is too specific to VS.
I am getting Issue Like :
1) Cannot Convert from TCHAR to Const Char*
2)cc1plus.exe: error: one or more PCH files were found, but they were invalid
3)cc1plus.exe: error: use -Winvalid-pch for more information
4)cc1plus.exe: fatal error: release\StdAfx.h: No such file or directory
5) error: conflicting declaration of C function 'int WinMain(HINSTANCE, HINSTANCE, LPTSTR, int)'
int _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
From these I came to conclusion that the code is more specific to Visual Studio.
I am using following tools pls correct me If I am not using correct version:
1)Qt Creator 3.6.1
Based on Qt 5.6.0 (MSVC 2013, 32 bit)
Is there any specific way to port code from VS2008 to Qt 5.6 or 5.7.
What you already did - I guess - is to migrate the visual studio project file to a Qt one. However, if you want to fully migrate to Qt and write a cross-platform application, you should replace all MFC-specific code to Qt, which is very different. For instance WinMain is (as expected) specific to windows: you should have a simple main. In there, you would need to define a QApplication, and so on...
My advice would probably be to start with some small Qt samples before tackling a full-fledged migration. You can then come back with more specific questions to stackoverflow if you get stuck.
Using MSVC compiler Could solved the Problem !!!!
It's just trivia.
Microsoft tried to introduce international characters to Windows too early, before the Unicode consortium had done its work, and got everything in a twist. So the Windows functions can be passing string about as various things, plain ascii, w_chars, TCHARS and so on. You need to make everything consistent. Every Windows function that takes a string has two forms, A for ascii or W for wide.
You need to make everything consistent and make sure the the functions are getting the right forms. Which might involve inserting a few glue functions to convert strings from wide to ascii and back.
There's nothing deeply wrong, but it is a bit of a job.

getProcAddressW errors when use visual studio2005 and windows mobile SDK to debug windows CE project

I am using Visual Studio 2005 and Windows Mobile 6 Professional Device SDK to debug a Windows CE project (copied from a Windows project ). I use active sync to connect PC and Win CE device. Then I create a new Windows CE project (copied from Windows project, but create using windows mobile 6 professional device SDK as platform. vc++, smart device, console app ).
When I build the windows CE project, there are some errors:
Error 1 error C2664: 'GetProcAddressW' : cannot convert parameter 2 from 'const char [21]' to 'LPCWSTR' xxxxx.cpp 42
It occurred after I used LoadLibrary(_T(xx.dll)); then I used GetProcAddress(handle,"functionName");
If I change it to use GetProcAddress(handle, _T("functionName") ); this error dispears. But
new error
LINK: error LNK2019: unresolved external symbol __imp_Function2
referenced in function wmain xxxx.obj
occured, Function2 is from another DLL project(both for windows and windows CE).
I don't know if I describe the problem clear, but I want to ask are there any way to make the source code that is both for Windows and windows CE when in the source code some functions are from different DLLs ?
Any answers are appriciated!
The first compiler error is somewhat self explanatory. get "W" at the end of GetProcAddressW means that the method is the wide character API (as opposed to GetProcAddressA, which is the ASCII version). Windows CE only exports the wide character versions of APIs. That means that you have to pass in a wide-character string. You used a TCHAR macro when you used _T, which makes the enclosed string a wide character literal, and the error goes away.
The same code should work fine on big Windows (for any recent version anyway), provided that you #define UNICODE (which is probably already on) and #include "tchar.h" which I think you since _T compiles. You could explicitly call GetProcAddressW instead of just GetProcAddress (which should be #defined to the wide version if UNICODE is defined).
The source linker error you see isn't clear. I'm guessing __imp_Function2 is a function pointer that you're trying to assign with the GetProcAddress call? Basically the linker isn't finding it, but the root cause isn't clear with the info you've provided.

Problem with Unicode in C++ exe (MSVC++2010)

I have a strange problem which I don't know where it came from. I might have changed some settings in the MSVC++2010 project but it all looks good to me.
I'm currently experimenting with the VSHADOW.EXE 3.0 tool included with Windows SDK 6.1. This is a sort of backup program written in C++ and the strings in it are composed of wchar_ts. Now, my arguments (such as -q) which I pass to the program always result in strings of japanese symbols in the program. This occurs if I start the program normally via cmd, but also if I specify commandline arguments in the Visual Studio project settings and start the debugger.
Does someone have an idea how to solve this problem? Thanks!
Problem solved, I changed wmain to main for a test and forgot to change it back.

Problem when disabling checked iterators in vs2008 SP1 (_HAS_ITERATOR_DEBUGGING=0)

I've been having some trouble with vs2008 SP1 running in debug mode when I try to disable checked iterators. The following program reproduces the problem (a crash in the string destructor):
#define _HAS_ITERATOR_DEBUGGING 0
#include <sstream>
int do_stuff(std::string const& text)
{
std::string::const_iterator i(text.end());
return 0;
}
int main()
{
std::ostringstream os;
os << "some_text";
return do_stuff(os.str());
}
I'd found a similar post on gamdev.net that discussed having this problem in vs2005. The example program in that post compiles for me on 2008 SP1 as is - but when I modded it to use ostringstream, I was able to get the problem.
From poking around in the debugger, it looks like the library pops iterators off the stack, then later tries to use them in _Orphan_All, which is some kind of iterator checking cleanup code...
Can anyone else reproduce this problem or tell me what's going on?
Thanks!
I've just tried this in VS2008 on Windows XP and got a warning regarding a buffer overflow, both on a pre- and a post-SP1 VS2008.
Interestingly enough the problem seems to be centred around passing the string into do_stuff either by reference or by value - if I use the original code, it complains about the buffer overflow but if I pass the string in by value, it runs fine. This is with the multithreaded debug DLL runtime. The error disappears when you like against the static MT Debug runtime.
In both cases, precompiled headers were turned off and the files that normally generate the precompiled headers have been removed from the project.
After reading this article on MSDN I'm wondering if the problem stems from the fact that several C++ standard library classes are actually residing in the runtime library if you build with the debug DLL runtimes (just try to link a VS2008-generated binary against an earlier library and watch out for the unresolved externals to confirm this).
It looks like this a known bug in VS2005 that was fixed in VS2005 SP1:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99655
Looks like this was submitted by the guy who posted about it on gamedev.net.
I'm not sure how or why it would have crept back into VS2008 (do you have headers from VS2005 that might be getting inthe way or something?)
Your code runs fine in Debug/Release mode on my VS2005. I have turned off precompiled headers and use the Multi-threaded DLL version of the runtime library.
Checked with VS2008 SP1 on a Vista machine (no precompiled headers, Multi-threaded DLL). Works just fine.
Check your install.
I reported the problem on the Microsoft website. They acknowledged the bug and say they've fixed it for the next version.
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=435483