DLLMain initialization routine failing

Giganews Newsgroups
Subject: DLLMain initialization routine failing
Posted by:  Jan Doggen
Date: Wed, 14 Jul 2010

I thought setting ExitCode=-1 (or any non-zero value) was the trick to not attaching the DLL.
But in the empty stub below, the ExitCode line makes the difference: if I leave it in I get GPFs all over.

What could be going on?
Thanks
Jan

{code}
library testcore;

uses
  SysUtils,
  Windows;

var
  CurrentEXE : String;

function IsExempted(EXEName: String): Boolean;
  var IsIE: Boolean;
  begin
    EXEName := Lowercase(EXEName);
    // We only hook Internet Explorer
    IsIE := (pos('iexplore.exe',EXEName) <> 0);
    Result := not IsIE;
  end; { IsExempted }

procedure ODS(const msg: String);
  begin
    OutputDebugString(PChar(Msg));
  end;

procedure DllMain(reason: Integer);
begin
  case reason of
    DLL_PROCESS_ATTACH: begin
                          CurrentEXE := Lowercase(ParamStr(0));
                          if IsExempted(CurrentEXE) then begin
                            ODS(CurrentEXE + ' is exempted');
                            ExitCode := -1;  (*** Problem ***)
                            end
                          else begin
                            ODS(CurrentEXE + ' initializing');
                            end;
                        end; { DLL_PROCESS_ATTACH }
    DLL_PROCESS_DETACH: begin
                          ODS(CurrentEXE + ' detaching');
                        end;
  end;
end; { DLLMain }

begin
  DllProc := @DllMain;
  DllProc(DLL_PROCESS_ATTACH);
end.

{code}

Replies