コード例 #1
0
        /// <summary>
        /// It is a constructor. Used to take over connection information.
        /// </summary>
        /// <param name="executeContextWindowHandle">
        /// Windowshandle that belongs to the target process.
        /// Operations are carried out in the thread of this window.
        /// <param name="bin">Connection information serialized binary.</param>
#else
        /// <summary>
        /// コンストラクタです。接続情報を引き継ぐときに使います。
        /// </summary>
        /// <param name="executeContextWindowHandle">接続対象プロセスの処理実行スレッドのウィンドウハンドル。</param>
        /// <param name="bin">接続情報がシリアライズされたバイナリ。</param>
#endif
        public WindowsAppFriend(IntPtr executeContextWindowHandle, byte[] bin)
        {
            ResourcesLocal.Initialize();
            ProtocolMessageManager.Initialize();
            _systemController = (SystemController)SerializeUtility.Deserialize(bin);
            _context          = new ExecuteContext(_systemController.StartFriendlyConnector(executeContextWindowHandle));
            NativeMethods.GetWindowThreadProcessId(executeContextWindowHandle, out _processId);
        }
コード例 #2
0
        /// <summary>
        /// Constructor.
        /// Connects to the process of the indicated window handle.
        /// Operations are carried out in the thread of the indicated window handle.
        /// </summary>
        /// <param name="executeContextWindowHandle">
        /// Windowshandle that belongs to the target process.
        /// Operations are carried out in the thread of this window.
        /// </param>
        /// <param name="clrVersion">
        /// CLR version of the target process. "v2.0.50727", "v4.0.30319"
        /// For more information please refer to the Microsoft site.
        /// To ensure backward compatibility, Friendly allows “2.0” for “v2.0.50727” and “4.0” for “v4.0.30319”, but these are now deprecated.
        /// For .NetCore, you can specify the full path of coreclr.dll.
        /// </param>
#else
        /// <summary>
        /// コンストラクタです。
        /// 指定のウィンドウハンドルのプロセスに接続します。
        /// また、指定のウィンドウハンドルのスレッドで処理が実行されます。
        /// </summary>
        /// <param name="executeContextWindowHandle">接続対象プロセスの処理実行スレッドのウィンドウハンドル。</param>
        /// <param name="clrVersion">CLRのバージョン "v2.0.50727", "v4.0.30319" のように入力してください。
        /// 詳細はマイクロソフトのサイトを参照お願いします。
        /// Friendlyの過去のバージョンとの互換性のため"v2.0.50727"は"2.0", "v4.0.30319"は"4.0"と入力することも可能ですが、今後これは非推奨となります。
        /// .NetCoreの場合はcoreclr.dllのフルパスを指定することができます。
        /// </param>
#endif
        public WindowsAppFriend(IntPtr executeContextWindowHandle, string clrVersion)
        {
            ResourcesLocal.Initialize();
            ProtocolMessageManager.Initialize();

            //プロセスの取得
            NativeMethods.GetWindowThreadProcessId(executeContextWindowHandle, out _processId);

            //サーバーを開始させる。
            _systemController = SystemStarter.Start(Process.GetProcessById(_processId), clrVersion, executeContextWindowHandle);

            //メインの実行ウィンドウハンドル生成。
            _context = new ExecuteContext(_systemController.StartFriendlyConnector(executeContextWindowHandle));

            //リソース初期化
            ResourcesLocal.Install(this);
        }
コード例 #3
0
        /// <summary>
        /// Constructor.
        /// Connects to the indicated process.
        /// Operations are carried out in the thread of the window that is the main window at connection time.
        /// </summary>
        /// <param name="process">Target application process.</param>
        /// <param name="clrVersion">
        /// CLR version of the target process. "v2.0.50727", "v4.0.30319"
        /// For more information please refer to the Microsoft site.
        /// To ensure backward compatibility, Friendly allows “2.0” for “v2.0.50727” and “4.0” for “v4.0.30319”, but these are now deprecated.
        /// For .NetCore, you can specify the full path of coreclr.dll.
        /// </param>
#else
        /// <summary>
        /// コンストラクタです。
        /// 指定のプロセスに接続します。
        /// この指定の場合、接続時のメインウィンドウのスレッドで処理が実行されます。
        /// </summary>
        /// <param name="process">接続対象プロセス。</param>
        /// <param name="clrVersion">CLRのバージョン "v2.0.50727", "v4.0.30319" のように入力してください。
        /// 詳細はマイクロソフトのサイトを参照お願いします。
        /// Friendlyの過去のバージョンとの互換性のため"v2.0.50727"は"2.0", "v4.0.30319"は"4.0"と入力することも可能ですが、今後これは非推奨となります。
        /// .NetCoreの場合はcoreclr.dllのフルパスを指定することができます。
        /// </param>
#endif
        public WindowsAppFriend(Process process, string clrVersion)
        {
            ResourcesLocal.Initialize();
            ProtocolMessageManager.Initialize();

            //アイドル状態になるのを待ちます。
            try
            {
                process.WaitForInputIdle();
            }
            catch
            {
                throw new FriendlyOperationException(ResourcesLocal.Instance.ErrorProcessOperation);
            }

            //メインウィンドウ取得待ち。
            while (process != null && process.MainWindowHandle == IntPtr.Zero)
            {
                try
                {
                    process = Process.GetProcessById(process.Id);
                }
                catch
                {
                    break;
                }
                Thread.Sleep(10);
            }
            if (process == null)
            {
                throw new FriendlyOperationException(ResourcesLocal.Instance.ErrorAppConnection);
            }
            _processId = process.Id;

            //サーバーを開始させる。
            _systemController = SystemStarter.Start(process, clrVersion, process.MainWindowHandle);

            //メインの実行ウィンドウハンドル生成。
            _context = new ExecuteContext(_systemController.StartFriendlyConnector(process.MainWindowHandle));

            //リソース初期化
            ResourcesLocal.Install(this);
        }