Attempt to call XVIRTUALSCREEN yielding build error

In my programming, I realized I need to start polling SM_CXVIRTUALSCREEN rather than SM_CXSCREEN in order to support users with multiple monitors.
However, when I tried to GetSystemMetrics (SM_CYVIRTUALSCREEN)) I got a build error and took advice from the Web that I needed to add multimon.h to my code.
So I got that file and added it to my source folder, and added
#include "multimon.h"
at the top of the source file that includes the GetSystemMetrics call.
And I added multimon.h to the project using Project | Add To Project | Files .
However when I try to build I get
"error LNK2001: unresolved external symbol _xGetSystemMetrics@4"

reggieperrinAsked:
Who is Participating?
 
AlexFMCommented:
Add lines
#define _WIN32_WINNT 0x0500
#define WIN32_WINDOWS 0x0410
#define WINVER  0x0500

before the line #include "windows.h", at least in the file where you use SM_CYVIRTUALSCREEN. This will fix your compilation error. You can see the following lines in winuser.h file:

#if(WINVER >= 0x0500)
#define SM_XVIRTUALSCREEN       76
#define SM_YVIRTUALSCREEN       77
#define SM_CXVIRTUALSCREEN      78
#define SM_CYVIRTUALSCREEN      79
...
#endif

This is the reason your code is not compiled now.

Your application can run on Win95/NT, because it calls function GetSystemMetrics which is supported in these OS. But result of call with SM_CYVIRTUALSCREEN is unpredictable, because this parameter is not supported. You need to do something on these operating systems, like show message that program doesn't support them. BTW, I don't think that virtual screens are supported on these OS.

So, your only problem is to say to compiler "Minimal target OS is W2K/98", and this is done by using these constants.

multimon.h is not related to this problem, maybe you need it for something else, I don't know.
0
 
AlexFMCommented:
What build error exactly did you get when added GetSystemMetrics (SM_CYVIRTUALSCREEN) call?
Notice that SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN constants are not supported in Win95 and NT. For every function and definition which is not supported in all operating systems, refer to the following article:

http://windowssdk.msdn.microsoft.com/en-us/library/ms736959.aspx
0
 
reggieperrinAuthor Commented:
"error C2065: 'SM_CYVIRTUALSCREEN' : undeclared identifier"

PS.  Thank you for pointing out the 95/NT issue. Does that mean that once I get multimon.h running properly, I will have to do the following?

OSVERSIONINFO      ver;
GetVersionEx(&ver);
if ((ver.dwPlatformId==VER_PLATFORM_WIN32_NT) || (ver.dwPlatformId==VER_PLATFORM_WIN32_95))
    GetSystemMetrics (SM_CXSCREEN);
else
    GetSystemMetrics (SM_CXVIRTUALSCREEN);


0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
AlexFMCommented:
No, this means that you need to add line:
#define _WIN32_WINNT 0x0500
before including windows.h. I don't think that you need multimon.h fot compiling SM_CXVIRTUALSCREEN.
0
 
reggieperrinAuthor Commented:
So, to make sure I understand, you are saying:
1. adding line: #define _WIN32_WINNT 0x0500 before the line #include "windows.h" in the 6 places that line occurs in my code will fix my build error.
2. adding line: #define _WIN32_WINNT 0x0500 before the line #include "windows.h" in the 6 places that line occurs in my code will ensure that my .exe runs on NT and 95.
3. I don't need to #include multimon.h at all, nor add it to my project.

Have I got this right? Thank you.
0
 
itsmeandnobodyelseCommented:
>>>> Add lines
>>>> #define _WIN32_WINNT 0x0500
>>>> #define WIN32_WINDOWS 0x0410
>>>> #define WINVER  0x0500

It's better to add these macros via Project Settings especially if using Precompiled Headers  (PCH). In that case, define statements prior to including stdafx.h (or whatever is the name of your PCH) were ignored.

You can add the macros in the Preprocessor settings of the C++ tab bei adding

    _WIN32_WINNT=0x0500 WIN32_WINDOWS=0x0410,WINVER=0x0500

to the existing preprocessor macros (e. g. WIN32).

Regards, Alex



0
 
reggieperrinAuthor Commented:
Thank you. I want my application to continue to be able to work on Win95 and WinNT.
You are correct that these platforms do non support multiple monitors (and I am fine if my application doesn't support multiple monitors for those OS, but I still want it run on those OS because we still have users on those OS).
0
 
reggieperrinAuthor Commented:
The answers have been helpful. However I was still hoping for clarity as to whether implementing the advice will result in failure of my application on Win95 and WinNT (as opposed to Win95 and WinNT users simply not getting optimal performance on multiple monitors).
0
 
itsmeandnobodyelseCommented:
>>>> I was still hoping for clarity as to whether implementing the advice will result in
>>>> failure of my application on Win95 and WinNT

GetSystemMetrics returns zero if the argument is unknown. You need to check the return value and perform some alternative code if 'virtual screen' options were not supported. You might read the following article to learn more: http://www.microsoft.com/msj/0697/monitor/monitor.aspx

So, there is no problem as long as you make sure to not calling functions that were not supported by W9x or NT, such as EnumDisplayMonitors. By defining the macros you make some more functions available which can be called on newer  Windows versions but would crash - cause they are not available - on the older versions. So, whenever using a WINAPI function where you don't know for sure that it is available on all platforms check the MSDN and do not call it on older platforms.

Regards, Alex






0
 
reggieperrinAuthor Commented:
Yes, I would rather we leave it open... sorry for the delay: I was out of town for a bit. I will test the final advice and then confirm whether it can be cleanly pointed and closed, if that is okay with you.
0
 
VenabiliCommented:
Any news here? It will get abandoned again in 3 days...
0
 
reggieperrinAuthor Commented:
Sorry about that. Thank you for splitting the points and closing it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.