Board index » delphi » Delphi App using C DLL Causing StackOverflow

Delphi App using C DLL Causing StackOverflow

Hello.

I have an application written in Delphi 5 which calls a DLL written in C. My
problem is that after a while, my app crashes with an EStackOverflow
exception. I have created a simple Console Application in Delphi and a
simple DLL in C to demonstrate my problem.

Any help would be greatly appreciated.

Here is the complete source:

Delphi Code:

program Project2;
{$APPTYPE CONSOLE}
uses
  SysUtils,
  Unit1 in 'Unit1.pas';

var
        retval          :Integer;
        test            :array [0..20] of char;
begin
        try
                while(true) do
                begin
                        retval := CrashTest2(test);
                end;
        except
        on e : exception do
                 showException(e,exceptAddr);
        end;
        Readln;
end.

unit Unit1;
interface
function CrashTest2(teststr :PChar):Integer;stdcall;external 'CrashDLL.dll';
implementation
end.

C DLL Code:

int    __declspec(dllexport)   CrashTest2(char *teststr)
{
 return 0;

Quote
}

Thanks in advance...

JB

 

Re:Delphi App using C DLL Causing StackOverflow


Assume it is a calling-convention problem, that the routine being called
isn't "stdcall" or that the parameters (e.g. integer-size) do not
conform.

Quote
jb wrote:

> Hello.

> I have an application written in Delphi 5 which calls a DLL written in C. My
> problem is that after a while, my app crashes with an EStackOverflow
> exception. I have created a simple Console Application in Delphi and a
> simple DLL in C to demonstrate my problem.

> Any help would be greatly appreciated.

> Here is the complete source:

> Delphi Code:

> program Project2;
> {$APPTYPE CONSOLE}
> uses
>   SysUtils,
>   Unit1 in 'Unit1.pas';

> var
>         retval          :Integer;
>         test            :array [0..20] of char;
> begin
>         try
>                 while(true) do
>                 begin
>                         retval := CrashTest2(test);
>                 end;
>         except
>         on e : exception do
>                  showException(e,exceptAddr);
>         end;
>         Readln;
> end.

> unit Unit1;
> interface
> function CrashTest2(teststr :PChar):Integer;stdcall;external 'CrashDLL.dll';
> implementation
> end.

> C DLL Code:

> int    __declspec(dllexport)   CrashTest2(char *teststr)
> {
>  return 0;
> }

> Thanks in advance...

> JB

--
----------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:i...@sundialservices.com  (PGP public key available.)

- Show quoted text -

Quote
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  Release 4.0 is here!!
> http://www.sundialservices.com/products/chimneysweep

Re:Delphi App using C DLL Causing StackOverflow


Thanks for your help.

I changing the line:
 function CrashTest2(teststr :PChar):Integer;stdcall;external
'CrashDLL.dll';
to:
function CrashTest2(teststr :PChar):Integer;cdecl;external 'CrashDLL.dll';

This appears to have fixed the problem.

Thanks again.

JB

Quote
"Sundial Services" <info_...@sundialservices.com> wrote in message

news:3C83CCD2.74A8@sundialservices.com...
Quote
> Assume it is a calling-convention problem, that the routine being called
> isn't "stdcall" or that the parameters (e.g. integer-size) do not
> conform.

> jb wrote:

> > Hello.

> > I have an application written in Delphi 5 which calls a DLL written in
C. My
> > problem is that after a while, my app crashes with an EStackOverflow
> > exception. I have created a simple Console Application in Delphi and a
> > simple DLL in C to demonstrate my problem.

> > Any help would be greatly appreciated.

> > Here is the complete source:

> > Delphi Code:

> > program Project2;
> > {$APPTYPE CONSOLE}
> > uses
> >   SysUtils,
> >   Unit1 in 'Unit1.pas';

> > var
> >         retval          :Integer;
> >         test            :array [0..20] of char;
> > begin
> >         try
> >                 while(true) do
> >                 begin
> >                         retval := CrashTest2(test);
> >                 end;
> >         except
> >         on e : exception do
> >                  showException(e,exceptAddr);
> >         end;
> >         Readln;
> > end.

> > unit Unit1;
> > interface
> > function CrashTest2(teststr :PChar):Integer;stdcall;external
'CrashDLL.dll';
> > implementation
> > end.

> > C DLL Code:

> > int    __declspec(dllexport)   CrashTest2(char *teststr)
> > {
> >  return 0;
> > }

> > Thanks in advance...

> > JB

> --
> ----------------------------------------------------------------
> Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
> mailto:i...@sundialservices.com  (PGP public key available.)
> > Fast(!), automatic table-repair with two clicks of the mouse!
> > ChimneySweep(R):  Release 4.0 is here!!
> > http://www.sundialservices.com/products/chimneysweep

Other Threads