1

I coded a C# screensaver which works in preview (install) mode, config or even test mode. However, when reaching the windows timer to launch it, screen goes black, I see the mouse loading icon for 2-3 sec and then the screen revert on the desktop.

I add a log file entry as the first line of code in my main() and it seems like this code is never run when launched by windows.

Using Visual studio 2017 on Windows 10.

Since I am using an old 3D engine, I made sure to have the app.config modified:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true"> 
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
      <supportedRuntime version="v1.1.4322"/>
    </startup>
</configuration>

I renamed Screensaver.exe to Screensaver.scr along with the app.config to Screensaver.scr.config. Copied these with my engine dll in SysWOW64 folder.

Build plateform target = x86.

I tried both debug and release build... And I used the same code structure to do a simple example of a screensaver displaying text and it worked therefore I really think the issue comes from the usage of the 3D engine dll.

Would you guys have any advice? Is there some specificities in the config that applies to a .scr? Can't find any lead anywhere and I am out of idea....

Here is the main code if it can help:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using TV3D;

namespace ScreenSaver
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            LogMessageToFile("Hello, World");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            CLTV3D tv3d = new CLTV3D();

            if (args.Length > 0)
            {
                string firstArgument = args[0].ToLower().Trim();
                string secondArgument = null;

                // Handle cases where arguments are separated by colon.
                // Examples: /c:1234567 or /P:1234567
                if (firstArgument.Length > 2)
                {
                    secondArgument = firstArgument.Substring(3).Trim();
                    firstArgument = firstArgument.Substring(0, 2);
                }
                else if (args.Length > 1)
                    secondArgument = args[1];

                if (firstArgument == "/c")           // Configuration mode
                {
                    Application.Run(new ScreenSaverSettingsForm());
                }
                else if (firstArgument == "/p")      // Preview mode
                {
                    if (secondArgument == null)
                    {
                        MessageBox.Show("Sorry, but the expected window handle was not provided.",
                            "ScreenSaver", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    IntPtr previewWndHandle = new IntPtr(long.Parse(secondArgument));
                    Application.Run(new TVForm(previewWndHandle, tv3d));


                }
                else if (firstArgument == "/s")      // Full-screen mode
                {
                    tv3d.TV.AddToLog("full screen mode argument detected");

                    foreach (Screen screen in Screen.AllScreens)
                    {
                        TVForm tv = new TVForm(screen.Bounds, screen.DeviceName, tv3d);
                        tv.Show();
                    }
                    Application.Run();
                }
                else    // Undefined argument
                {
                    MessageBox.Show("Sorry, but the command line argument \"" + firstArgument +
                        "\" is not valid.", "ScreenSaver",
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else    // No arguments - treat like /c
            {
                Application.Run(new ScreenSaverSettingsForm());
            }
        }



        static public string GetTempPath()
        {
            string path = System.Environment.GetEnvironmentVariable("TEMP");
            if (!path.EndsWith("\\")) path += "\\";
            return path;
        }

        static public void LogMessageToFile(string msg)
        {
            System.IO.StreamWriter sw = System.IO.File.AppendText(
                GetTempPath() + "My Log File.txt");
            try
            {
                string logLine = System.String.Format(
                    "{0:G}: {1}.", System.DateTime.Now, msg);
                sw.WriteLine(logLine);
            }
            finally
            {
                sw.Close();
            }
        }


    }
}
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
Windrider
  • 57
  • 6

1 Answers1

0

Looks like you've narrowed it down to the 3d component.

Without the log file you can be sure the application fails to start, and without an error message it's hard to diagnose why. Here are some troubleshooting steps.

Try:

  • the event logs for clues,
  • to 'late bind' CLTV3D using Assembly.Load in a Try/Catch,
  • running ProcessMonitor to see it says about why it's failing.

If the above doesn't work setup DebugDiag (or AdPlus with WinDbg and SOS) and analyze a crash dump.

Failing that, .Net 1.1 is like 15yrs old!!! Do yourself a favor, it will be so much easier to use an up to date library.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Thanks for the leads, much appreciated. Translating the french exception.message : "The mix mode assembly is created with runtime version 'v1.1.4322' and cannot be loaded in 4.0 runtime without other configuration information." Would that mean that the .scr does not really consider the Screensaver.scr.config or is there other configuration to do that I am not aware of? I know I should change my engine. I'm just a hobby programmer a little too comfy in his old stuff and indeed I shall shake me a little to upgrade... – Windrider Aug 05 '17 at 15:46
  • *Mix Mode assembly?* Unmanaged/Managed? Try to get it working in a WinForm app, also is .net 1.1 installed? – Jeremy Thompson Aug 05 '17 at 15:50
  • Yeah, I have worked with that many other time for different codes. It is working in a winform. Simply not when launched by the windows screensaver timer... – Windrider Aug 05 '17 at 15:54
  • CC the vendor, under a debugger it might be a quick fix for them in VS2003 – Jeremy Thompson Aug 05 '17 at 15:56
  • 1
    on such an old engine.... I shall have a quicker solution switching to another library! :) – Windrider Aug 05 '17 at 15:58
  • I will accept you answer as the solution since although the problem was not fixed, the answer was the way as to how to precisely identify the trouble. thanks for you assistance. – Windrider Aug 05 '17 at 16:00