Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8500077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:50:39+00:00 2026-06-11T00:50:39+00:00

My 3.5 .NET Framework program handles multiple monitors, so I use Screen.DeviceName to distinguish

  • 0

My 3.5 .NET Framework program handles multiple monitors, so I use Screen.DeviceName to distinguish between different monitors (can’t just compare references to the instances of the Screen object — different instances can refer to the same screen).

The program works no problem on Windows 7, but on Windows XP SP3 with all .NET frameworks installed it would randomly do strange things, as if it failed to realise that the two given screens are in fact the same screen, which it should be able to recognize as they should have identical DeviceNames.

What is the problem and how do I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:50:41+00:00Added an answer on June 11, 2026 at 12:50 am

    There appears to be a bug somewhere in the framework or in Windows XP.

    If you dump a Screen.DeviceName under Windows 7, you will get something like

    \\.\DISPLAY1
    \\.\DISPLAY2

    But if you do the same on Windows XP, you will get something like

    \\.\DISPLAY1    ????A??M?↕?☺  ?
    \\.\DISPLAY2    ????☺ ? ☺ ?????

    Apparently Microsoft was aware of the bug, so they put a note in the documentation:

    This string may contain non-printable characters.

    And that would be perfectly okay if the non-printable characters were the same each time.
    But they are not, because in fact, they are garbage, random memory contents that goes after the terminating null character.

    If you create just one cached instance of the Screen object and call its DeviceName property several times, the garbage will be the same each time, because the Screen object caches the name in itself. But if you create a new instance of the Screen object for each request, then the garbage is likely to be different for these instances, even if they refer to the same device:

    System.Windows.Forms.Screen s = null;
    System.Drawing.Point p = new System.Drawing.Point(0,0);
    
    Console.WriteLine("Using same instance of Screen:");
    s = System.Windows.Forms.Screen.FromPoint(p);
    for (int i = 0; i < 5; ++i)
    {
        Console.WriteLine(s.DeviceName);
    }
    
    Console.WriteLine();
    
    Console.WriteLine("Using new instance of Screen:");
    for (int i = 0; i < 5; ++i)
    {
        Console.WriteLine(System.Windows.Forms.Screen.FromPoint(p).DeviceName);
    }
    

    If you run this snippet on Windows XP, you will get something like:

    enter image description here

    Note how you have at least three versions of DeviceName here.

    On Windows 7, on contrary, the garbage part will be stripped out.

    This is why the code fails to recognize screens — device names are different each time.

    To fix that, crop the DeviceName string after the first '\0' character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if I implemented a program with different threads working, can I rely .Net framework
As I can see, beta2 of .Net Framework 4.0 installation program is only 55MB,
I'm developing a client-server program. I use C# programming language and .net framework 4.
My question is why would a .net program operate differently between different computers (both
I'm trying to use C# and the .NET Framework 4.0 to make a program
The .NET framework ships with 6 different hashing algorithms: MD5: 16 bytes (Time to
I am making a program for handheld PDAs using .net 2.0 compact framework and
The program I'm working on in C# (.Net Framework 2.0) calls for the ability
I am writing a program which is targeted to run on .net framework 2.0.
I'm currently rewriting an old VB6 program in C# in the .Net Framework 2.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.