[scilab-Users] Re: Linking Delphi DLL with Scilab

Allan CORNET allan.cornet at scilab.org
Wed May 23 12:29:00 CEST 2012


Hi,

Please open a bug report @ bugzilla.scilab.org
(In all case, Scilab must not crash here but to return an error message)

Your Delphi DLL must be compiled with cdecl (default C calling convention)
calling convention to link in Scilab (Please attach dll in your bug report)

http://en.wikipedia.org/wiki/X86_calling_conventions

Thanks

Allan
-----Message d'origine-----
De : cbeckmann [mailto:christianbeckman at web.de] 
Envoyé : mercredi 23 mai 2012 12:22
À : users at lists.scilab.org
Objet : [scilab-Users] Re: Linking Delphi DLL with Scilab

Hi,

I have problems at calling procedures from a DLL compiled with Delphi
(actually Turbo Delphi). Linkage to the DLL obviously seems to work. 

Although tested at different Scilab versions, for example 5.3.3, Scilab
always shows the same warning:"Scilab has found a critical error
(EXCEPTION_ACCESS_VIOLATION) with "call" function."

The DLL and Scilab versions are 32bit. But I use Windows XP 64bit.

Maybe someone could help me with the code. I can't find any error.  I am
also a little bit wondering why I should use the stdcall calling convention
as the Scilab help recommends the cdecl calling convention for C-code.
Nonetheless, stdcall calling convention didn't work neither.

The Turbo Delphi Code is as follows:
/library Project4;

{$R *.res}
type PointerLongInt =  ^LongInt;    // LongInt should be 32bit in Turbo
Delphi
var
a_global, b_global: LongInt;


procedure AddIntegers(a, b: PointerLongInt); cdecl; begin
  a_global:=a^;
  b_global:=b^;
end;

procedure GetResult(c: PointerLongInt); cdecl; begin
  c^ := 9;
end;

exports
   AddIntegers, GetResult;
 
begin
end./

The scilab code is as follows:
/DLLpath='c:\Programmierung\Delphi_DLL_CouplingWithScilab\Project4.dll';
try
  x=link(DLLpath, ['AddIntegers', 'GetResult'], 'c'); catch
  mprintf('\n Error!!!!!!! Linkage to .dll failed' + ascii(10));
  abort;
end;

a=2;
b=2;
c=0;
d=0;

a=iconvert(a, 4);
b=iconvert(b, 4);
c=iconvert(c, 4);
d=iconvert(d, 4);

try
  mprintf('\n First Call\n');
  call("AddIntegers", a, 1, "i", b, 2, "i") catch
  mprintf('\n Error in First Call');
end;
try
  mprintf('\n Second Call\n');
  c= call("GetResult", "out",[1,1],1,"i") catch
  mprintf('\n Error in Second Call ');
end;
ulink(x);/

Surprisingly, the first call didn't work, but the second did. But I am not
that sure about the properties of the integer type in the call function, but
i guess it should be unsigned 32bit, or?

Is there also anybody who has successfully called functions inside a Delphi
DLL and could send me a short test code or similar?


--
View this message in context:
http://mailinglists.scilab.org/Linking-Delphi-DLL-with-Scilab-tp3967008p4008
362.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at
Nabble.com.

--
To unsubscribe from this mailing-list, please send an empty mail to
users-unsubscribe at lists.scilab.org
To check the archives of this mailing list, see
http://mailinglists.scilab.org/





More information about the users mailing list