Interfacing with matlab dlls from Delphi
Posted on 2010-11-18
I am trying to use functions written in Matlab from Delphi. The test function is very simple, it just adds one to an input variable as follows:
function [Output] = AddOne(Input)
I've managed to compile it ok and access the dll from delphi, but I get an access violation at the line where I try to use the function.
l define the function in Delphi as follows:
In the interface:
function MatlabFunc(NRetValues: Integer;var Output: Variant;var Input: Variant): Variant; cdecl;
In the implementation:
function MatlabFunc(NRetValues: Integer;var Output: Variant;var Input: Variant): Variant; cdecl; external 'AddOne.dll' name '_mlxAddOne';
Then call it:
I've installed all the relevant matlab runtime libraries and everything seems to work ok, I think it's just a matter of figuring out the correct calling convention. Or do I have to use mclInitializeApplication or something? It does appear from web searches that people have had similar problems and that some people have managed to solve it, but no-one explains quite how.