Re: Problems when calling functions from a .dll



I have two guesses given the limited information you have supplied.

1. The function return value should probably just be double not double*
2. Your functions are probably stdcall (frequently called WINAPI) so try
adding __stdcall to the function:

double __stdcall FunctionNameInTheDll (double* , double*);

Phil

"Ingo Leusbrock" <Ingo.Leusbrock@xxxxxx> wrote in message
news:ef1dd13.-1@xxxxxxxxxxxxxxxxxxx
> Hello everyone!
>
> I have quite some problems with calling functions from a .dll. I
> assume that this is more or less due to my rather small knowledge
> when it comes to the structure of dll's and working with FORTRAN and
> not because the problem is so complicated (I am an engineer, no
> computer scientist ;-) ).
> The situation is as this:
> I have a .dll-file; originally written in Fortran and compiled by
> Compaq Visual Fortran Compiler. The .lib is also available, but the
> source code is missing since the .dll is part of a commercial
> software package. The original purpose of this package was to import
> the .dll to Excel with a .xla-file as an Add-In (this works fine so
> far). All functions, input and output values are defined as DOUBLE
> PRECISION (double in Matlab); the arguments are transfered BY
> REFERENCE and the values of the functions are given back BY VALUE.
> My idea was now to import the .dll to Matlab. Since the header file
> is missing, I used the function declaration used in the .xla-file
> /code
> Declare Function xyz Lib "mydll.DLL" (ByRef x As Double, ByRef y As
> Double) As Double
> /codeoff
>
> as a basic for my header file, which is based on the example file
> delivered by Matlab (shrlibsample.h):
> /code
>
> #ifndef myheader_h
> #define myheader_h
>
> /* Function declarations */
> EXPORTED_FUNCTION double* FunctionNameInTheDll (double* , double*)
> ;
>
> #endif
>
> /codeoff
>
> (There are several functions in the .dll, some have just one double
> as input. But that is not the problem.)
> So far so good. From this point on my problems start. When I now try
> to call the function via 'calllib('myDLL','myFunction', Pointer1,
> Pointer2)' I get a matlab crash. What I already tried was to work
> without pointers and to use the syntax of the examples in the
> shrlibsample.c . More or less with no sucess.
> As a solution I have thought of sending my matlab variables to Excel,
> let the .dll do its work there and send the data back to Matlab. But
> this is no real situation, more a workaround and I do not know, how
> this will influence the calculation time if I have to send/receive
> the data to Excel rather often (esp. when I have to do iterations).
>
> So, if anyone can give me some advice, it would be very muc h
> appreciated.
>
> P.S.: Another solution might be to call the .dll in Fortran and then
> send the data to Matlab, since the .dll was originally was written in
> Fortran. I assume that there might be less problems there, but I am
> rather clueless when it comes to Fortran/working with MEX-Files.


.



Relevant Pages

  • Re: Segmentation fault when accessing function in a DLL
    ... Matlab crashes when the last line is executed. ... If I try to initialize these fields 'Serial' and 'Value' as well before the libpointer statement, ... I am trying to use functions in a windows DLL for controlling stepper motor hardware. ... % The USMCDLL.h header file must be located on the current Matlab path. ...
    (comp.soft-sys.matlab)
  • Re: interfacing generic dll with matlab
    ... return values of the functions in your DLL. ... A header file is only one ... described in the Matlab documentation first to understand how Matlab ... information is organized in the prototype file. ...
    (comp.soft-sys.matlab)
  • Re: &quot;calllib&quot; functions in a DLL build by MINGW / GNU Compiler
    ... >> But any function call gives me an exception. ... >> returning back to matlab. ... Is there a special way to build the dll to ... > Post the header file. ...
    (comp.soft-sys.matlab)
  • C DLL WITH MATLAB
    ... I've got a query about how matlab works with dll. ... dll that has define constants in the header file. ... ViConstString triggerID, ...
    (comp.soft-sys.matlab)
  • loadlibrary Fortran DLL - no header file
    ... I've got a DLL written and compiled in Digital Fortran with a function ... I want to use in Matlab. ... did not come with a c-style ".h" header file. ... I tried creating my own "hfile" from scratch using the ...
    (comp.soft-sys.matlab)