Solved

Attempt to call XVIRTUALSCREEN yielding build error

Posted on 2006-06-24
16
674 Views
Last Modified: 2012-06-21
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"

0
Comment
Question by:reggieperrin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
16 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16977935
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
 

Author Comment

by:reggieperrin
ID: 16978534
"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
 
LVL 48

Expert Comment

by:AlexFM
ID: 16978617
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:reggieperrin
ID: 16978707
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 16978791
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 16985359
>>>> 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
 

Author Comment

by:reggieperrin
ID: 16995921
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
 

Author Comment

by:reggieperrin
ID: 17237023
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
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 250 total points
ID: 17239787
>>>> 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
 

Author Comment

by:reggieperrin
ID: 17438358
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
 
LVL 20

Expert Comment

by:Venabili
ID: 17549854
Any news here? It will get abandoned again in 3 days...
0
 

Author Comment

by:reggieperrin
ID: 17686824
Sorry about that. Thank you for splitting the points and closing it.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
is twain_32.dll cmpatible with windows 10 ? 10 232
best sources to up-to-date in C++? 8 103
max float value 3 59
Gaming Software 1 29
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question