小さい頃はエラ呼吸

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


MFCに動的にリンクされる通常のMFC DLL(google翻訳)

はじめに

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

ここから導入部

A regular MFC DLL dynamically linked to MFC is a DLL that uses MFC internally, and the exported functions in the DLL can be called by either MFC or non-MFC executables. As the name describes, this kind of DLL is built using the dynamic-link library version of MFC (also known as the shared version of MFC). Functions are usually exported from a regular MFC DLL using the standard C interface.

MFCに動的にリンクされる通常のMFC DLLは、MFCを内部的に使用するDLLであり、DLL内のエクスポートされた関数は、MFCまたは非MFC実行可能ファイルのいずれかによって呼び出すことができます。名前が示すように、この種類のDLLは、ダイナミックリンクライブラリバージョンのMFC(MFCの共有バージョンとも呼ばれます)を使用して構築されます。関数は通常、標準のCインターフェイスを使用して通常のMFC DLLからエクスポートされます。

You must add the AFX_MANAGE_STATE macro at the beginning of all the exported functions in regular MFC DLLs that dynamically link to MFC to set the current module state to the one for the DLL. This is done by adding the following line of code to the beginning of functions exported from the DLL:

現在のモジュール状態をDLLの状態に設定するために、MFCに動的にリンクする通常のMFC DLLのすべてのエクスポートされた関数の先頭にAFX_MANAGE_STATEマクロを追加する必要があります。これを行うには、DLLからエクスポートされた関数の先頭に次のコード行を追加します。

AFX_MANAGE_STATE(AfxGetStaticModuleState( ))

A regular MFC DLL, dynamically linked to MFC has the following features:

  • This is a new type of DLL introduced by Visual C++ 4.0.
  • The client executable can be written in any language that supports the use of DLLs (C, C++, Pascal, Visual Basic, and so on); it does not have to be an MFC application.
  • Unlike the statically linked regular MFC DLL, this type of DLL is dynamically linked to the MFC DLL (also known as the shared MFC DLL).
  • The MFC import library linked to this type of DLL is the same one used for MFC extension DLLs or applications using the MFC DLL: MFCxx(D).lib.

MFCに動的にリンクされた通常のMFC DLLには、次の機能があります。

  • これは、Visual C ++ 4.0で導入された新しいタイプのDLLです。
  • クライアント実行可能ファイルは、DLL(C、C ++、Pascal、Visual Basicなど)の使用をサポートする任意の言語で作成できます。 MFCアプリケーションである必要はありません。
  • 静的にリンクされた通常のMFC DLLとは異なり、このタイプのDLLはMFC DLL(共有MFC DLLとも呼ばれます)に動的にリンクされます。
  • このタイプのDLLにリンクされたMFCインポートライブラリは、MFC拡張DLLまたはMFC DLLを使用するアプリケーションに使用されるものと同じです:MFCxx(D).lib。

A regular MFC DLL, dynamically linked to MFC has the following requirements:

  • These DLLs are compiled with _AFXDLL defined, just like an executable that is dynamically linked to the MFC DLL. But _USRDLL is also defined, just like a regular MFC DLL that is statically linked to MFC.
  • This type of DLL must instantiate a CWinApp-derived class.
  • This type of DLL uses the DllMain provided by MFC. Place all DLL-specific initialization code in the InitInstance member function and termination code in ExitInstance as in a normal MFC application.

MFCに動的にリンクされる通常のMFC DLLには、次の要件があります。

  • これらのDLLは、MFC DLLに動的にリンクされる実行可能ファイルのように、_AFXDLLが定義されてコンパイルされます。ただし、MFCに静的にリンクされている通常のMFC DLLと同様に、_USRDLLも定義されています。
  • このタイプのDLLは、CWinApp派生クラスをインスタンス化する必要があります。
  • このタイプのDLLは、MFCが提供するDllMainを使用します。通常のMFCアプリケーションと同様に、InitInstanceメンバー関数にすべてのDLL固有の初期化コードを、ExitInstanceに終了コードを配置します。

Because this kind of DLL uses the dynamic-link library version of MFC, you must explicitly set the current module state to the one for the DLL. To do this, use the AFX_MANAGE_STATE macro at the beginning of every function exported from the DLL.

この種類のDLLはダイナミックリンクライブラリバージョンのMFCを使用するため、現在のモジュールの状態をDLLの状態に明示的に設定する必要があります。これを行うには、DLLからエクスポートされたすべての関数の先頭でAFX_MANAGE_STATEマクロを使用します

regular MFC DLLs must have a CWinApp-derived class and a single object of that application class, as does an MFC application. However, the CWinApp object of the DLL does not have a main message pump, as does the CWinApp object of an application.

通常のMFC DLLには、MFCアプリケーションと同様に、CWinApp派生クラスとそのアプリケーションクラスの単一オブジェクトが必要です。ただし、DLLのCWinAppオブジェクトには、アプリケーションのCWinAppオブジェクトとは異なり、メインメッセージポンプがありません。

Note that the CWinApp::Run mechanism does not apply to a DLL, because the application owns the main message pump. If your DLL brings up modeless dialogs or has a main frame window of its own, your application's main message pump must call a DLL-exported routine that calls CWinApp::PreTranslateMessage.

アプリケーションがメインメッセージポンプを所有しているため、CWinApp :: RunメカニズムはDLLに適用されないことに注意してください。 DLLがモードレスダイアログを表示するか、独自のメインフレームウィンドウを持っている場合、アプリケーションのメインメッセージポンプは、CWinApp :: PreTranslateMessageを呼び出すDLLエクスポートルーチンを呼び出す必要があります。

Place all DLL-specific initialization in the CWinApp::InitInstance member function as in a normal MFC application. The CWinApp::ExitInstance member function of your CWinApp derived class is called from the MFC provided DllMain function before the DLL is unloaded.

通常のMFCアプリケーションと同様に、CWinApp :: InitInstanceメンバー関数にすべてのDLL固有の初期化を配置します。 CWinApp派生クラスのCWinApp :: ExitInstanceメンバー関数は、DLLがアンロードされる前に、MFCが提供するDllMain関数から呼び出されます。

You must distribute the shared DLLs MFCx0.dll and Msvcr*0.dll (or similar files) with your application.

A DLL that is dynamically linked to MFC cannot also statically link to MFC. Applications link to regular MFC DLLs dynamically linked to MFC it just like any other DLL.

Symbols are usually exported from a regular MFC DLL using the standard C interface. The declaration of a function exported from a regular MFC DLL looks something like this:

共有DLL MFCx0.dllおよびMsvcr * 0.dll(または同様のファイル)をアプリケーションと共に配布する必要があります。

MFCに動的にリンクされているDLLは、MFCに静的にリンクすることもできません。アプリケーションは、他のDLLと同様に、MFCに動的にリンクされる通常のMFC DLLにリンクします。

シンボルは通常、標準のCインターフェイスを使用して通常のMFC DLLからエクスポートされます。通常のMFC DLLからエクスポートされた関数の宣言は次のようになります。

extern "C" __declspec(dllexport) MyExportedFunction( );

All memory allocations within a regular MFC DLL should stay within the DLL; the DLL should not pass to or receive from the calling executable any of the following:

  • pointers to MFC objects
  • pointers to memory allocated by MFC

通常のMFC DLL内のすべてのメモリ割り当ては、DLL内にとどまる必要があります。 DLLは、次のいずれかを呼び出し実行可能ファイルに渡したり、呼び出し実行可能ファイルから受け取ったりしないでください

  • MFCオブジェクトへのポインター
  • MFCによって割り当てられたメモリへのポインタ

If you need to do any of the above, or if you need to pass MFC-derived objects between the calling executable and the DLL, then you must build an MFC extension DLL.

It is safe to pass pointers to memory that were allocated by the C run-time libraries between an application and a DLL only if you make a copy of the data. You must not delete or resize these pointers or use them without making a copy of the memory.

When building a regular MFC DLL that dynamically links to MFC, you need to use the macro AFX_MANAGE_STATE to switch the MFC module state correctly. This is done by adding the following line of code to the beginning of functions exported from the DLL:

上記のいずれかを実行する必要がある場合、または呼び出し実行可能ファイルとDLLの間でMFC派生オブジェクトを渡す必要がある場合は、MFC拡張DLLをビルドする必要があります。

データのコピーを作成する場合にのみ、アプリケーションとDLLの間でCランタイムライブラリによって割り当てられたメモリにポインタを渡すことは安全です。これらのポインターを削除またはサイズ変更したり、メモリーのコピーを作成せずに使用したりしないでください。

MFCに動的にリンクする通常のMFC DLLを構築するときは、マクロAFX_MANAGE_STATEを使用してMFCモジュールの状態を正しく切り替える必要があります。これを行うには、DLLからエクスポートされた関数の先頭に次のコード行を追加します。

AFX_MANAGE_STATE(AfxGetStaticModuleState( ))

The AFX_MANAGE_STATE macro should not be used in regular MFC DLLs that statically link to MFC or in MFC extension DLLs. For more information, see Managing the State Data of MFC Modules.

For an example of how to write, build, and use a regular MFC DLL, see the sample DLLScreenCap. For more information about regular MFC DLLs that dynamically link to MFC, see the section titled "Converting DLLScreenCap to Dynamically Link with the MFC DLL" in the abstract for the sample.

AFX_MANAGE_STATEマクロは、MFCに静的にリンクする通常のMFC DLLまたはMFC拡張DLLでは使用しないでください。詳細については、MFCモジュールの状態データの管理を参照してください。

通常のMFC DLLの作成、ビルド、および使用方法の例については、サンプルDLLScreenCapを参照してください。 MFCに動的にリンクする通常のMFC DLLの詳細については、サンプルの要約の「DLLScreenCapをMFC DLLに動的にリンクする変換」セクションを参照してください。