Announcement

Collapse
No announcement yet.

Delphi 6.01: DLL_PROCESS_DETACH-Bug in einer DLL

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Delphi 6.01: DLL_PROCESS_DETACH-Bug in einer DLL

    Von Norbert Nather stammt die folgende Fehlermeldung:

    <i>Beim entladen einer DLL wird die DLLProc Routine nach Umstellen auf Delphi 6 nicht mehr ausgeführt.</i>
    <pre>
    procedure LibraryProc(Reason: Integer);
    begin
    case Reason of
    DLL_PROCESS_DETACH : ShowMessage('0');
    DLL_PROCESS_ATTACH : ShowMessage('1');
    end;
    end;

    begin
    DllProc := @LibraryProc;
    LibraryProc(DLL_PROCESS_ATTACH);
    end.
    </pre>
    <i>Kann mir jemand sagen was ich hier falsch mache? oder ist das auch wieder ein Bug von Delphi6? </i>

    Ich habe dieses Problem über das Beispielprojekt aus meinem Buch <i>Delphi Win32-Lösungen</i> (Kapitel DLL\Import\Dynamisch) nachvollziehen können:
    <pre>
    procedure DLLHandler(aReason : Integer);
    var
    szInfo : array[0..29] of Char;
    begin
    case aReason of
    DLL_Process_Detach : szInfo := 'DLL wird entladen.';
    DLL_Thread_Attach : szInfo := 'Thread wird erzeugt.';
    DLL_Thread_Detach : szInfo := 'Thread terminiert.';
    end;
    MessageBox(0, szInfo, 'DLL-Handler', mb_IconInformation);
    end;

    exports
    SetDLLText,
    GetDLLText;

    begin
    // Unit-System -> Variable »DLLProc« initialisieren
    DLLProc := @DLLHandler;
    // DLL-Daten initialisieren
    szDLLText := 'Standardzeichenkette';
    end.
    </pre>
    Ergebnis:<br>
    a) DLL + EXE wird mit Delphi <b>5</b> compiliert: MessageBox "DLL wird entladen" erscheint <br>
    b) DLL + EXE wird mit Delphi <b>6</b> compiliert: MessageBox erscheint <b>nicht!</b>

    Fazit: <b>Bug in Delphi 6</b>

  • #2
    Betrifft Delphi 6(5?) unter Win2000 (XP?)

    Quelle: http://community.borland.com/article/0,1410,27753,00.html

    QUESTION:
    Why isn't DLLPROC being called when my DLL is unloaded?

    ANSWER:

    Due to RTL changes, the DLLProc was not being called appropriately. This change will fix the change that you may have noticed. Once you have completed the change, you will need to recompile the RTL and copy the new System.dcu into your project directory. Your project will use the newly created System.dcu with the fix included. In System.pas, navigate down to this method @@skipTLSproc.
    <PRE>
    @@skipTLSproc:

    { Call any DllProc }

    PUSH ECX
    MOV ECX,[ESP+8]//Changed from 4 to 8.
    TEST ECX,ECX
    JE @@noDllProc
    MOV EAX,[EBP+12]
    MOV EDX,[EBP+16]
    CALL ECX
    </PRE&gt

    Comment

    Working...
    X