別のプロセス内で挿入された DLL を使用しています。この DLL では、1 つのスレッドを作成して、とりわけ 2 つのタイマーを設定し、KeyboardHook (SetWindowsHookEx WH_KEYBOARD_LL) を実行します... このフックと 2 つのタイマーを機能させるには、1 つのメッセージ ポンプ プロシージャを作成する必要がありました。そして、Thread.Execute でわかるように、この Message Pump を Thread の最後のものとして呼び出します。
procedure MyMainThread.Execute;
begin
while not Terminated do
begin
MyThread:= Self;
StartKeyboardHook;
StartUp;
SetTimer(0, 0, 60000, @MyMainThread.ContactHome);
SetTimer(0, 0, 40000, @MyMainThread.MapProc);
CreateMessagePump;
Terminate;
end;
end;
CreateMessagePump 呼び出しの後、Terminate を実行します。これは、メッセージ ポンプが 1 つの無限ループであると信じているためです。それから抜け出すと、何か問題が発生するため、スレッドを終了する必要があります。CreateMessagePump は次のとおりです。
procedure MyMainThread.CreateMessagePump;
var
AppMsg: TMsg;
begin
while GetMessage(AppMsg, 0, 0, 0) do
begin
TranslateMessage(AppMsg);
DispatchMessage(AppMsg);
end;
//if needed to quit this procedure use PostQuitMessage(0);
end;
私はこれを正しい方法でやっていますか?つまり、このループが無限であると信じるのは正しいですか?