procedure _StartLib(Context: PInitContext; Module: PLibModule; DLLProc: TDLLProcEx);<br>var<br> TempSwap: TInitContext;<br>begin<br> // Context's register save fields are already initialized.<br> // Save the current InitContext and activate the new Context by swapping them<br> TempSwap := InitContext;<br> InitContext := PInitContext(Context)^;<br> PInitContext(Context)^ := TempSwap;<br><br> InitContext.Module := Module;<br> InitContext.OuterContext := Context;<br><br> // DLLInitState is initialized by SysInit to 0 for shutdown, 1 for startup<br> // Inc DLLInitState to distinguish from package init:<br> // 0 for package, 1 for DLL shutdown, 2 for DLL startup<br><br> Inc(InitContext.DLLInitState);<br><br> if InitContext.DLLInitState = 1 then<br> begin<br> InitContext.InitTable := Module.InitTable;<br> if Assigned(InitContext.InitTable) then<br> InitContext.InitCount := InitContext.InitTable.UnitCount // shutdown<br> end<br> else<br> begin<br> Module.InitTable := InitContext.InitTable; // save for shutdown<br> InitContext.InitCount := 0; // startup<br> end;<br><br> if Assigned(DLLProc) then<br> DLLProc(InitContext.DLLInitState-1,0);<br><br> if MainInstance = 0 then { Set IsLibrary if there was no exe yet }<br> begin<br> IsLibrary := True;<br> Default8087CW := Get8087CW;<br> end;<br><br> if InitContext.DLLInitState = 1 then<br> _Halt0<br> else<br> InitUnits;<br>end;<br>{$ENDIF}