Q&A

  • 부탁[Dll에서의 에러]
그냥 소스를 올려놓으면...



Procedure LibraryCall(Mainapp : TApplication; Const Dllname, ProcName : String);

Type

TProc = Procedure(Mainapp : TApplication; Const Dllname, ProcName : String);StdCall;

Var

PROC : TProc;

begin

H := LoadLibrary(Pchar(DllName));

If H < 32 Then Begin

ShowMessage('DLL이 존재하지 않습니다!.');

Exit;

End;



@PROC := GetProcAddress(H, Pchar('Call_TEST01'));

If not (@PROC = nil) Then

PROC(Mainapp,Pchar(DllName),Pchar(ProcName));

End;



procedure TForm1.BitBtn2Click(Sender: TObject);

begin

FreeLibrary(H);

Close;

end;



Dll은 사용에는 문제가 없는데 Close할때



Project TEST_P.exe raised exception class EAccessViolation with message 'Access violation at address 00000000. Read if address 00000000'. Process stopped. Use Step or Run to continue.

라는 메시지가 나옵니다.



제생각으론 메모리 해제를 하고 다시 Close를 해서 그런것 같은데...

어떻게 해야 합니까



꼭 좀 답변 부탁드립니다.

2  COMMENTS
  • Profile
    bingyou 2001.11.09 20:19
    moon wrote:

    > 그냥 소스를 올려놓으면...

    >

    > Procedure LibraryCall(Mainapp : TApplication; Const Dllname, ProcName : String);

    > Type

    > TProc = Procedure(Mainapp : TApplication; Const Dllname, ProcName : String);StdCall;

    > Var

    > PROC : TProc;

    > begin

    > H := LoadLibrary(Pchar(DllName));

    > If H < 32 Then Begin

    > ShowMessage('DLL이 존재하지 않습니다!.');

    > Exit;

    > End;

    >

    > @PROC := GetProcAddress(H, Pchar('Call_TEST01'));

    > If not (@PROC = nil) Then

    > PROC(Mainapp,Pchar(DllName),Pchar(ProcName));

    > End;

    >

    > procedure TForm1.BitBtn2Click(Sender: TObject);

    > begin

    > FreeLibrary(H);

    > Close;

    > end;

    >

    > Project TEST_P.exe raised exception class EAccessViolation with message 'Access violation at address 00000000. Read if address 00000000'. Process stopped. Use Step or Run to continue.

    > 라는 메시지가 나옵니다.

    >

    > 제생각으론 메모리 해제를 하고 Close를 해서 그런것 같은데...

    > 어떻게 해야 합니까

    >

    > 꼭 좀 답변 부탁드립니다.



    FreeLibrary(H);

    이 넘을 LibraryCall에다가 넣으시면 될것 같은데...자신은 없습니다만...

    이렇게요...



    ...



    If not (@PROC = nil) Then

    PROC(Mainapp,Pchar(DllName),Pchar(ProcName));

    FreeLibrary(H);

    ...





  • Profile
    moon 2001.11.09 20:51
    bingyou wrote:

    > moon wrote:

    > > 그냥 소스를 올려놓으면...

    > >

    > > Procedure LibraryCall(Mainapp : TApplication; Const Dllname, ProcName : String);

    > > Type

    > > TProc = Procedure(Mainapp : TApplication; Const Dllname, ProcName : String);StdCall;

    > > Var

    > > PROC : TProc;

    > > begin

    > > H := LoadLibrary(Pchar(DllName));

    > > If H < 32 Then Begin

    > > ShowMessage('DLL이 존재하지 않습니다!.');

    > > Exit;

    > > End;

    > >

    > > @PROC := GetProcAddress(H, Pchar('Call_TEST01'));

    > > If not (@PROC = nil) Then

    > > PROC(Mainapp,Pchar(DllName),Pchar(ProcName));

    > > End;

    > >

    > > procedure TForm1.BitBtn2Click(Sender: TObject);

    > > begin

    > > FreeLibrary(H);

    > > Close;

    > > end;

    > >

    > > Project TEST_P.exe raised exception class EAccessViolation with message 'Access violation at address 00000000. Read if address 00000000'. Process stopped. Use Step or Run to continue.

    > > 라는 메시지가 나옵니다.

    > >

    > > 제생각으론 메모리 해제를 하고 Close를 해서 그런것 같은데...

    > > 어떻게 해야 합니까

    > >

    > > 꼭 좀 답변 부탁드립니다.

    >

    > FreeLibrary(H);

    > 이 넘을 LibraryCall에다가 넣으시면 될것 같은데...자신은 없습니다만...

    > 이렇게요...

    >

    > ...

    >

    > If not (@PROC = nil) Then

    > PROC(Mainapp,Pchar(DllName),Pchar(ProcName));

    > FreeLibrary(H);

    > ...

    >

    >

    그렇게 하니까

    바로 해제가 되네요

    그래서 뜨지가 않네요

    dll부르고 바로 해제

    또 문제가 Close를 못 시키네요 화면이 사라져 버려서...

    만약 화면이 사라지지 않는다 해도 close를 하면 같은 결과를 가지고 오지 않을까요

    누구 좀 갈쳐 주세요