Why does Window geometry change when migrating from VS2010 to VS2017? - c++

I have a large Win API C++ Application that i recently moved from Visual Studio 2010 to 2017. Application compiles, links and runs now, but i find that the window borders are about 2 pixels larger than before.
This is a problem as we implemented docking windows long time ago with 100% own code. Although all sizes are retrieved from the OS using GetSystemMetrics etc. this turned out to need some more specific alignment. It took a lot of development time when developing (for Windows 2000) and retargeting later for Windows 7. Furthermore we have some small windows and the thicker frames just waste space.
So i installed the Windows SDK 7.1 and was able after some tweaks to install that. But i am not able to choose 7.1 in the project settings. Typing in that in the project settings results in
error MSB8036: The Windows SDK version 7.1 was not found.
Although I find a directory named:
C:\Program Files\Microsoft SDKs\Windows\v7.1
Also when trying to re-target the Project, the SDK 7.1 is not listed.
I did a lot of googling and found this and that but no substantial answer. msdn is horrible.
Questions (obsolet, see below):
Is it possible to use VC 2017 with Windows 7 SDK? How?
Is there possibly a different way to keep the geometry used with VC2010?
EDIT:
I don't think that this is a duplicate of Dialog border different after porting code from Visual Studio 6 to Visual Studio 2013 although the link is quite helpful. It turned out, that different values are returned for GetSystemMetrics(SM_CYFRAME). So far I do not see a substantial explanation for that. Please see my own answer and comments.
So let me update the question:
Why does the value returned from GetSystemMetrics(SM_CYFRAME) change when upgrading from VC2010 to VC2017?
What is the root cause?

Is it possible to use VC 2017 with Windows 7 SDK? How?
Yes, but I doubt this is the solution to your main problem.
Is there possibly a different way to keep the geometry used with VC2010?
Yes, just change the minimum subsystem version to pre-Vista value, like 5.01 (for Windows XP 32-bit). For some reason, 5.1 will yield the same result too; the resulting EXE would be the same.
When Win32 Subsystem Version is 6.0 or above, there is a behavior change regarding the window border size. Though I am not aware of where Microsoft has documented about this.
If you still have Windows 7, the difference is also obvious when you are using Windows Basic theme, as shown in this screenshot:
Screenshot added by RED SOFT ADAIR:

It turned out that the problem was as described here:
https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/eaae1445-264d-487f-aba1-52dfc8abdfe4/getsystemmetrics-difference-in-return-value-for-the-same-input?forum=windowssdk
The value returned for GetSystemMetrics(SM_CXFRAME) changed with VS 2013.
In VS2010 (Window 8.1)
GetSystemMetrics(SM_CXFRAME); // 8 pixels
In VS2013 (Window 8.1, same PC)
GetSystemMetrics(SM_CYFRAME); // 4 pixels
In VC2013 and later the same result will be returned using
GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
My windows still had the same frame size. I miss interpreted the root cause.
Still i do not understand how this can happen. By my understanding GetSystemMetrics is a function of the Windows OS. How can this function behave different when changing the compiler? I guess this IS part of the Windows SDK?
By the way, i found, that i can select "Windows 7.1" as the Platform Toolset, but not for the SDK (as i was thinking).
All this is confusing. Can anybody point out the differences and the junctions between SDK and Toolset?
EDIT:
I made a little sample program to prove this:
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv)
{
printf("GetSystemMetrics(SM_CXFRAME) returns: %d\n", GetSystemMetrics(SM_CXFRAME));
return 0;
}
Compiling with VC2010 results in "8".
Compiling with VC2017 results in "4".
Even if i choose "dont upgrade" for the SDK when migrating to VC2017.
If you dont believe it - try yourself.
If you have any more insights to that - you're welcome. I give you a 500 points bounty!

Related

My program doesn't run on some PCs

I'm working in a project building an application with Computer Vision using C++, OpenCV and Visual Studio. I'm no expert in deploying programs to use them on other PCs.
I've made a program which I need to distribute to a certain amount of people and I can't make it work on all the computers I'd like to. The program was written using Visual Studio 2015, it's an MFC Project and the code is written in C++ since I'm using OpenCV.
When it was finished, I tried to run it on another computer and I realized that it won't open. I looked on the Internet and found out that I needed to statically link the libraries, so I did it. Also, when I was looking for information, I found that Visual Studio 2015 builds its projects so you can run the programs on machines with Win7 to Win10. When I learnt that, I tried to open it on PCs running Windows 7, 8, 8.1 and 10. I tested my program in like 20 computers, give or take.
The results? I couldn't make it work for Windows 7, the error ucrtbase.terminate api-ms-win-crt-runtime-l1-1-0.dll showed every time I tried to open it. It also didn't open in one machine with Windows 8 without showing any error message, but it DID open on most of the machines with Win 8.1 and Win 10. The thing is that "most"; there were some PCs (with Win 8.1 and 10) that I couldn't open my program on. I found that sometimes it would show up in the Task Manager for less than a second and then disappear. The most stressful thing is that it doesn't tell me what the problem is, it doesn't show any error message. It just won't open.
I tried using Dependency Walker (both on my PC and one of those that I couldn't run my program on) to see if there's something missing and I got a reeaaally long list of files that the system couldn't find, here's an example:
List 1/11. Something curious is that my program executes just well on my computer and on those I could open it, even though Dependency Walker (DW) tells me that there might be a problem with it. This indicates me that DW is not finding the exact error I'm having.
Another thing I've tried is to compare the things I have installed on my computer and install them on the one I want to execute my program on. I tried installing .NET Framework 4.6.1 just because VS 2015 says that my project was built using it (and I have it installed in my PC and that other one doesn't. Also I tried with .NET 4.6.1 SDK). Nothing changed.
Just look here:
https://msdn.microsoft.com/de-de/library/ms235299.aspx
The quick-and-dirty way would be to copy the DLLs from your redist directory. For my MS VS 2013 it is hidden under the VS installation directory in:
VC\redist\x86
or
VC\redist\x64
...
which depends on your application.

"Missing MSCVP140.dll" and "Missing VCRUNTIME140.dll" when running an .exe-File on another computer

I made a program in Microsoft Visual Studio C++ and used the SFML for this. I included the correct .dll-Files, that the program needed, and copied them into the "Release"-Folder. It worked. The entire program worked flawless on my computer, but as soon as I tried to run it on another computer, it said: Missing "MSVCP140.dll" and Missing "VCRUNTIME140.dll.
I searched for a solution of this program, and always heared "Go to Project > Project Settings > C/C++ > Code generation > Runtime libraries > switch to Multi-Threaded (/MT). I compiled the project with this settings, and the executable increased in size, which they said is normal, because there are no supporting .dll-Files anymore.
But as I tried it again, with the new .exe, it gave me the exact same Error-Messages. Are there any other possibilities to solve this WITHOUT installing some -dll-Files onto the computer?
This is covered on MSDN in some detail. See Deployment in Visual C++
You really have three choices:
Use the "centralized" versions of the DLLs. For this you should have a setup program that runs the VCREDIST_*.EXE packages for VS 2015 or if using a MSI-based setup you can use the MSM files provided.
Copy the required DLLs as part of your program. This means your installer or zip file or whatever that has the EXE includes the DLLs it needs too. This is the best choice if you want "copy and run" style deployment, but remember that all security servicing of the DLL is now your problem.
Use static linking. From a security perspective this is the least desired solution, and really should only be used in the specific cases of writing an installer--i.e. the program that installs an app has to run in the first place.
You have not specified which version of Windows is running on your target machine. VS 2015 does not support Windows 7 RTM as it's out of support, but it does support Windows 7 Service Pack 1 along with Windows Vista Service Pack 2, Windows 8.x, and Windows 10.
While we are on the subject note that Windows 8.0 is also out of support. Those users need to upgrade to Windows 8.1 Update or Windows 10.

api-ms-win-core-synch-l1-2-1.dll is missing from your computer

I am developing a C/C++ application using Visual Studio Community 2015.
I used to build my application the system library: OneCoreUAP.lib. I am using Windows 8.1.
I used the function if_nametoindex defined in https://msdn.microsoft.com/en-us/library/windows/hardware/ff553788%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
In the link they specifies that you require ONeCOreUAP.lib
but I found Another links that indicates another library: Iphlpapi.lib: https://msdn.microsoft.com/en-us/library/windows/desktop/bb408409%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
When launching my app I getting the following error:
The program can't start because api-ms-win-core-synch-l1-2-1.dll is missing from your computer.
Try reinstalling the program to fix this problem.
This is the message image:
When searching the dll, I know from the this link:
https://msdn.microsoft.com/en-us/library/windows/desktop/mt657574(v=vs.85).aspx
that:
Introduced into api-ms-win-core-synch-l1-2-1.dll in Windows 10.0.10240.0
I tried to update the Windows 10 SDK, But this did not solve the problem.
How to solve the problem? Should I upgrade my windows 8.1 to windows 10 to solve it?
The page you found appears to have to do with Windows drivers that link against the Universal App Platform runtime, which is only available in Windows 10 and up. OneCoreUAP.lib is the .lib file that represents the UAP runtime. If someone who knows more about this could enlighten me on the specifics of this, that would be helpful; I don't fully understand what's going on or how and hwy it works.
You are not writing one of these; instead, you are writing a desktop program. So instead, you want to look at the desktop program documentation. Usually this is the first thing that Googling for the function name in question will get you. In your case, this is that page, and at the bottom of the page it says the function can be found in Iphlpapi.lib, so you must link aganst that .lib file instead.
The bottom of that page also says the function was introduced no later than Windows Vista, so you are able to use it on 8.1.

VS2010 Intellisense problems

This question actually is an implicit answer, since I could fix the problem in the meantime for myself. But I wanted to publish my experience, since some other developers might have a similar problems.
The problem:
I am using VS2010 prof SP1 on Windows XP SP3, pure C++ only. (AntiVirus software present).
Since some days Intellisense - which is quite helpful under normal conditions - does not work anymore.
Things tried:
created a new simple console application. -> Intellisense still not working.
resetting VS-Settings by means of Tools/Import & Export Settings/Reset. -> Intellisense still not working
Changes to option settings in Text-Editor/C++/Advanced inclusive logging did not help.
-> Intellisense still not working
There was actually an interesting observation:
Intellisense normally creates a directory 'ipch' in the solution directory to store intermediate files. In my solution folders it disappeared as soon as the solution was opened. When I created a folder 'ipch' and opened the solution Intellisense removed the folder again - strange.
The final fix:
During the last week some new Windows updates were installed. I noticed some other unusual behaviour of my PC as well. After having created an image of my PC, I decided to
uninstall Windows updates from 2013-09-11 (4 packages) and one update from 2013-08-28.
(unfortunately I did not note down the KB-numbers)
AND: out of a sudden Intellisense is working again !
Maybe this report could be helpful for some other persons.
Automatic Updates are now disabled on my PCs.
Confirmed 100%
Microsoft Visual Studio 2010 Version 10.0.30319.1 RTMRel
Microsoft NET framework 4.0.30319 RTMRel
Microsoft Windows XP Professional Version 2002 Service Pack 3
Intellisense stops working after installing KB2876217.
Intellisense is back after removing update.
I had the same problem and also had the idea that one of the Windows Updates is buggy, so I can confirm your report.
I tried to uninstall them one-b<-one and found the "bad guy":
KB2876217 destroys intellisense for VS2010 under XP SP3.
A supported hotfix is available from Microsoft to fix this issue. Check at http://support.microsoft.com/kb/2526044/en-us
Actually, it may not be such a good idea to uninstall update KB2876217. Instead, install Visual Studio SP1 update (if not already installed) and then install update KB2526044. I have tried it before and it does work...

Crash on Windows 7 but running on XP

i've written a small application using c++, Qt and Visual Studio 2010. It's working on Windows XP (32bit) but it crashes on Windows 7 (64 bit) right after start-up. I see a "The program has stopped working..." error. Do I have to recompile the application for Windows 7? And is it possible to get more information why it crashes?
Thanks
In general you wouldn't have to recompile for windows 7, but it depends on your application which you haven't provided details of.
The easiest way to find out is either debug it in windows 7 or put more error handling in, so that it lets you know what has gone wrong, or where it has gone wrong
I agree with what martiert said, also, if you are using some external elements, images. sound files, video files, etc ... be sure of the file location asd this was a problem for me when I was presenting my graduation project, I moved the whole solution from a directory to another and it crashed because it was reading a not found directory ... so be sure of the links of the images, videos, sounds etc ...
You might have to recompile for Windows 7/64bit. It might not even work after a recompile, since Windows 7 is not XP, and a program written for 32 bit might not work for 64. Often one don't have to recompile, but sometimes one have to, and some times a program which works on XP won't work on Windows 7.