Try this one, see what you come up with.
First, you forgot to specifically state the calling convention used.
Generally speaking, you should always use 'stdcall' - search Help for
it. Then, you should not use '@var <> nil', always use 'Assigned(var)'.
type
TDLLsample: function(): Integer; stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
DLLHandle: THandle;
fnDLLsample: TDLLsample;
begin
DLLHandle := LoadLibrary('dllsample.dll');
if DLLHandle <> 0 then
begin
@fnDllsample := GetProcAddress(DLLHandle, 'fnDllsample');
if Assigned(fnDllsample) then
begin
i := fnDllsample;
ShowMessage(IntToStr(i));
end;
end;
end;
end.
--- In [email protected], "Tuan Le" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> 1. I have created a dll in Visual C by wizard
> (File/New/Project/Win32 Dynamic-link Libary and select "A dll that
exports
> some symbols")
>
> I built it and my dll is : dllsample.dll
>
> In this dll, there is a sample function
>
> DLLSAMPLE_API int fnDllsample(void)
> {
> return 42;
> }
>
> 2. I also create a project in delphi. DllHandle is always not NULL but
> @fnDllsample is null.
>
> It seems fnDllsample does not export but I can call this function DLL in
> visual c. Delphi can't
> Please help me, how to call it.
>
> Many thanks,
> Tuan
>
> (attached file : dllsample.zip)
>
> -------------------------------------------
>
> My code is below:
>
> var
> fnDllsample: function(): integer;
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
> i : integer;
> DLLHandle: THandle;
>
> begin
>
> DLLHandle := LoadLibrary('dllsample.dll');
> if DLLHandle <> 0 then
> begin
> @fnDllsample := GetProcAddress(DLLHandle,'fnDllsample');
> if @fnDllsample <> nil then
> begin
> i := fnDllsample;
> showmessage(inttostr(i));
> end;
> end;
> end;
>
> end.
>
>
> [Non-text portions of this message have been removed]
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/