Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Function in DLL got Access Violation

Posted on 2008-10-08
4
1,153 Views
Last Modified: 2012-08-13
Hello,

Whats wrong in my code?

I got access violation after Close the form, a empty form...

What is wrong here?

Best Regards,
Carlos


[EXE]
 
function CallMyDLLFunc: Boolean;
type
  TMyDLLFunc = record
    Func: function: BOOL; StdCall;
    hLib: THandle;
  end;
var
  MyDLLFunc: TMyDLLFunc;
begin
  Result := False;
  with MyDLLFunc do
  begin
    hLib := LoadLibrary(PChar('dll.dll'));
    if hLib <> 0 then
    begin
      @Func := GetProcAddress(hLib, 'MyDLLFunc');
      if Assigned(Func) then
      Result := Func;
      FreeLibrary(hLib);
    end;
  end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  if CallMyDLLFunc then
  ShowMessage('OK');
end;
 
----------------------------------------------------------------------
[DLL]
 
function MyDLLFunc: BOOL; StdCall;
begin
  Result := False;
  Form1 := TForm1.Create(nil);
  try
    Form1.ShowModal;
    Result := Form1.bResult; //bResult is Boolean in Public
  finally
    Form1.Release;
    Form1 := nil;
  end;
end;
 
exports
  EULA name 'EULA';

Open in new window

0
Comment
Question by:cebasso
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
ChristianWimmer earned 500 total points
ID: 22671734
0
 
LVL 4

Author Closing Comment

by:cebasso
ID: 31504365
Thanks :DD
Regards,
Carlos
0
 
LVL 6

Expert Comment

by:JosephGlosz
ID: 22671877
this line
     @Func := GetProcAddress(hLib, 'MyDLLFunc');

should be
     @Func := GetProcAddress(hLib, 'Eula);

then, inside your DLL, the function name should be Eula as well, so change
  function MyDLLFunc: BOOL; StdCall;
to
  function Eula: BOOL; StdCall;

Or, if you want to call the function MyDLLFunc, then you should "export" it as such.

0
 
LVL 4

Author Comment

by:cebasso
ID: 22671945
JosephGlosz thanks for reply, but i just got the code and changed the original name of the Function, its really EULA but i changed here to MyDLLFunc just as example.
Anyway my problem was solved changing .Release to .Free
Thanks anyway!
Regards!
Carlos
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 92
Run video youtube webbrowse 10 65
Delphi IDE crash without error message ... 7 99
how to change, disabled button color FMX ? 1 40
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question