cebasso
asked on
Function in DLL got Access Violation
Hello,
Whats wrong in my code?
I got access violation after Close the form, a empty form...
What is wrong here?
Best Regards,
Carlos
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';
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
@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.
ASKER
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
Anyway my problem was solved changing .Release to .Free
Thanks anyway!
Regards!
Carlos
ASKER
Regards,
Carlos