小さい頃はエラ呼吸

いつのまにやら肺で呼吸をしています。


MFCモジュールの状態データの管理(google翻訳)

はじめに

マイクロソフト社のMFC DLLの日本語翻訳説明が機械翻訳すぎて言ってることが全然分からないので、google翻訳にしてみました。
docs.microsoft.com

導入文

This article discusses the state data of MFC modules and how this state is updated when the flow of execution (the path code takes through an application when executing) enters and leaves a module. Switching module states with the AFX_MANAGE_STATE and METHOD_PROLOGUE macros is also discussed.

この記事では、MFCモジュールの状態データと、実行フロー(実行時にパスコードがアプリケーションを通過する)がモジュールに出入りするときにこの状態がどのように更新されるかについて説明します。 AFX_MANAGE_STATEおよびMETHOD_PROLOGUEマクロを使用したモジュール状態の切り替えについても説明します。

The term "module" here refers to an executable program, or to a DLL (or set of DLLs) that operate independently of the rest of the application, but uses a shared copy of the MFC DLL. An ActiveX control is a typical example of a module.

!注意
ここでの「モジュール」という用語は、アプリケーションの他の部分とは独立して動作するが、MFC DLLの共有コピーを使用する実行可能プログラム、またはDLL(またはDLLのセット)を指します。 ActiveXコントロールは、モジュールの典型的な例です。

As shown in the following figure, MFC has state data for each module used in an application. Examples of this data include Windows instance handles (used for loading resources), pointers to the current CWinApp and CWinThread objects of an application, OLE module reference counts, and a variety of maps that maintain the connections between Windows object handles and corresponding instances of MFC objects. However, when an application uses multiple modules, the state data of each module is not application wide. Rather, each module has its own private copy of the MFC's state data.

次の図に示すように、MFCにはアプリケーションで使用される各モジュールの状態データがあります。このデータの例には、Windowsインスタンスハンドル(リソースのロードに使用)、アプリケーションの現在のCWinAppおよびCWinThreadオブジェクトへのポインター、OLEモジュールの参照カウント、およびWindowsオブジェクトハンドルとMFCの対応するインスタンス間の接続を維持するさまざまなマップが含まれますオブジェクト。ただし、アプリケーションが複数のモジュールを使用する場合、各モジュールの状態データはアプリケーション全体ではありません。むしろ、各モジュールにはMFCの状態データの独自のプライベートコピーがあります。
f:id:replication:20190922055326p:plain

A module's state data is contained in a structure and is always available via a pointer to that structure. When the flow of execution enters a particular module, as shown in the following figure, that module's state must be the "current" or "effective" state. Therefore, each thread object has a pointer to the effective state structure of that application. Keeping this pointer updated at all times is vital to managing the application's global state and maintaining the integrity of each module's state. Incorrect management of the global state can lead to unpredictable application behavior.

モジュールの状態データは構造体に含まれており、その構造体へのポインターを介して常に利用可能です。次の図に示すように、実行フローが特定のモジュールに入ると、そのモジュールの状態は「現在の」または「有効な」状態でなければなりません。したがって、各スレッドオブジェクトには、そのアプリケーションの有効な状態構造へのポインタがあります。このポインターを常に最新の状態に保つことは、アプリケーションのグローバル状態を管理し、各モジュールの状態の整合性を維持するために不可欠です。グローバル状態の不適切な管理は、予測できないアプリケーションの動作につながる可能性があります。
f:id:replication:20190922055400p:plain

State Data of Multiple Modules

In other words, each module is responsible for correctly switching between module states at all of its entry points. An "entry point" is any place where the flow of execution can enter the module's code. Entry points include:

  • Exported functions in a DLL
  • Member functions of COM interfaces
  • Window procedures

複数のモジュールの状態データ

つまり、各モジュールは、すべてのエントリポイントでモジュールの状態を正しく切り替える責任があります。 「エントリポイント」とは、実行フローがモジュールのコードを入力できる場所です。エントリポイントは次のとおりです。