Ok, I figured it out myself. For some reason the Visual basic only passes the first entry of each vector to the DLL, but in Matlab the entire vector needs to be passed.
Retrieving array from calllib
3 views (last 30 days)
Show older comments
Steven Feingold
on 1 Jul 2014
Answered: Steven Feingold
on 1 Jul 2014
I have a DLL that I'm trying to use in Matlab, and I'm basing my code off a successful call of the DLL that I have in Excel using Visual Basic. In Visual Basic the code to call the DLL looks like this:
Call CurveFitFunc(x(1), y(1), nr, results(1), initParams(1))
Where 'x' and 'y' are vectors that a curve is being fit to, 'nr' is the length of the vector, 'results' and 'initParams' are vectors containing only zeros (lengths 5 and 4 respectively). When called in Visual Basic, the function updates the entries in 'results' and 'initParams' with the values that I want.
I've been able to load and run the dll in Matlab, but rather than updating the input vectors, Matlab outputs only single values to new variables. Is this an issue with pointers, or something that Matlab can't do?
Here is the Visual Basic declaration:
Public Declare Sub CurveFitFunc Lib "C:\Excel Add-ins\...\DLLNAME.dll" (xValues As Double, yValues As Double, ByVal xlen As Long, results As Double, initParams As Double)
And here is the header file that I'm using for Matlab:
void _stdcall CurveFitFunc(double *xValue, double *yValue, int xlen, double *results, double *initParams);
Finally, here is the result from libfunctionsview:
[doublePtr, doublePtr, doublePtr, doublePtr] CurveFitFunc (doublePtr, doublePtr, int32, doublePtr, doublePtr)
I've never called DLLs before, so anything that might point me in the right direction is helpful.
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on COM Component Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!