1

プレビュー (インストール) モード、構成、またはテスト モードで動作する C# スクリーンセーバーをコーディングしました。ただし、起動するために Windows タイマーに到達すると、画面が黒くなり、マウスの読み込みアイコンが 2 ~ 3 秒間表示された後、画面がデスクトップに戻ります。

コードの最初の行としてログ ファイル エントリを追加しましたmain()が、Windows で起動したときにこのコードが実行されないようです。

Windows 10 で Visual Studio 2017 を使用しています。

私は古い 3D エンジンを使用しているので、app.config を変更したことを確認しました。

<?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>

Screensaver.exe を Screensaver.scr に、app.config を Screensaver.scr.config に名前を変更しました。これらを SysWOW64 フォルダーのエンジン dll と一緒にコピーしました。

ビルド プラットフォーム ターゲット = x86。

デバッグビルドとリリースビルドの両方を試しました...そして、同じコード構造を使用して、テキストを表示するスクリーンセーバーの簡単な例を実行しましたが、機能したため、問題は3Dエンジンdllの使用に起因すると本当に思います.

何かアドバイスはありますか?.scr に適用される構成にいくつかの特異性はありますか? どこにもリードが見つからず、私は考えが及ばない....

役立つ場合のメインコードは次のとおりです。

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();
            }
        }


    }
}
4

1 に答える 1

0

3D コンポーネントに絞り込んだようです。

ログ ファイルがなければ、アプリケーションの起動に失敗したことを確認できます。エラー メッセージがなければ、その理由を診断するのは困難です。トラブルシューティングの手順を次に示します。

試す:

  • 手がかりのイベントログ、
  • Assembly.LoadTry/Catch で使用する CLTV3D を「レイト バインド」するには、
  • ProcessMonitor を実行して、なぜ失敗したのかを確認します。

上記が機能しない場合は、DebugDiag (または WinDbg と SOS を使用した AdPlus) をセットアップし、クラッシュ ダンプを分析します。

それができなければ、.Net 1.1 は 15 年前のものです!!! 最新のライブラリを使用する方がはるかに簡単です。

于 2017-08-05T04:34:06.257 に答える