Board index » delphi » Little DLL Crashes My Little App?

Little DLL Crashes My Little App?

I wrote a little 'Hello World' DLL then wrote a single button app to call
it.  The little app crashes after executing the dll.  The app call looks
like this:
    procedure opnDll(i: SmallInt); external 'myapp.dll';
    procedure TForm1.Button1Click(Sender: TObject);
var x: SmallInt;
begin
   x := StrToInt(edit1.text);
   opnDll(x);
   showmessage('done');
end;

The dll looks like this:
    procedure opnDll(i: SmallInt) stdCall;
    begin
    if i = 0 then
         showmessage('101: hello world'+#10+'s = 0'+#10+IntToStr(i))
   else
          showmessage('101: hello world'+#10+'x <> 0'+#10+IntToStr(i))
    end;

I've tried passing integer, pchar, smallint and also return values boolean,
integer, etc..  I'm using D5.  Any suggestions welcome.

Thanks, -Bob

 

Re:Little DLL Crashes My Little App?


you have the DLL function declared as STDCALL and you have your app calling it
as register call..
you must match the call types.
 in your APP specify STDCALL when you declare your DLL function..
Quote
Bob Pless wrote:
> I wrote a little 'Hello World' DLL then wrote a single button app to call
> it.  The little app crashes after executing the dll.  The app call looks
> like this:
>     procedure opnDll(i: SmallInt); external 'myapp.dll';
>     procedure TForm1.Button1Click(Sender: TObject);
> var x: SmallInt;
> begin
>    x := StrToInt(edit1.text);
>    opnDll(x);
>    showmessage('done');
> end;

> The dll looks like this:
>     procedure opnDll(i: SmallInt) stdCall;
>     begin
>     if i = 0 then
>          showmessage('101: hello world'+#10+'s = 0'+#10+IntToStr(i))
>    else
>           showmessage('101: hello world'+#10+'x <> 0'+#10+IntToStr(i))
>     end;

> I've tried passing integer, pchar, smallint and also return values boolean,
> integer, etc..  I'm using D5.  Any suggestions welcome.

> Thanks, -Bob

Other Threads