Board index » delphi » Calling my DLL without Access Violation

Calling my DLL without Access Violation

Hy!

I compiled a complete program as a dll by changing the project unit in a
library unit and exporting a procedure called 'init' that runs the
Application.xxx commands.

Now I have a second program, that calls the library so:

procedure TForm1.Button1Click(Sender: TObject);
type
    TInit = procedure();
var
   Handle: THandle;
   Init: TInit;
begin
     Handle := LoadLibrary('Mydll.dll');
     @Init := GetProcAddress(Handle, 'Init');
     Init;
end;

If I start this program and I click on Button1 delphi shows me an exception
typ: EAccessViolation and nothing happens.

Can someone help me?

 

Re:Calling my DLL without Access Violation


1) You should check whether your DLL is really loaded (HANDLE > 33 i think)
   There is a corresponding constant in Windows.pas

2) You should check if "Init" is assigned !
   Warning: GetProcAddress is case sensitive.

Thomas Illig a crit dans le message <8778rp$17e...@chico.franken.de>...

Quote
>Hy!

>I compiled a complete program as a dll by changing the project unit in a
>library unit and exporting a procedure called 'init' that runs the
>Application.xxx commands.

>Now I have a second program, that calls the library so:

>procedure TForm1.Button1Click(Sender: TObject);
>type
>    TInit = procedure();
>var
>   Handle: THandle;
>   Init: TInit;
>begin
>     Handle := LoadLibrary('Mydll.dll');
>     @Init := GetProcAddress(Handle, 'Init');
>     Init;
>end;

>If I start this program and I click on Button1 delphi shows me an exception
>typ: EAccessViolation and nothing happens.

>Can someone help me?

Re:Calling my DLL without Access Violation


Thank YOU!

I renamed all procedures and variables into lowercase and now it's running!

Other Threads