libmatrix.h library for C/C++ DLL importing
2 次查看(过去 30 天)
显示 更早的评论
Hi! I am trying to import a DLL generated by the Matlab compiler SDK. The DLL has the following function declaration in its header file:
mlfAdd(int nargout, mxArray** sum, mxArray* operand1, mxArray* operand2);
Invoking this function requires the creation and instantiation of 2 mxArray* data types and the creation of a third non-instantiated mxArray** as an output parameter.
From what I can find in the Matlab documentation on calling a shared library , I need to import libmatrix.h in order to invoke mxCreate functions that will return a pointer to an mxArray in memory from the data that I wish to pass into it. So, in theory, I should be able to write a C file like so:
#include <matrix.h> // compiles
#include <libmatrix.h> // compilation error, libmatrix.h does not exist
#include <stdlib.h>
#include <windows.h>
typedef double (CALLBACK* DLL_FUNCTION_PTR_MLFADD)(int, mxArray**, mxArray*, mxArray*);
int main()
{
// Declare mxArrays
mxArray *mxOperand, *mxOperator;
mxArray *sum = NULL;
mxOperand = // an mxCreate function that I can't write since I don't have
// a libmatrix.h with information on mxCreate functions
mxOperator = // an mxCreate function that I can't write since I don't have
// a libmatrix.h with information on mxCreate functions
// Load and invoke the DLL function
HINSTANCE hDLL;
hDLL = LoadLibrary("BasicMathFunctions"); // BasicMathFunctions is what I named my library
if (hDLL != NULL) {
DLL_FUNCTION_PTR_MLFADD mlfAddPtr = (DLL_FUNCTION_PTR_MLFADD)GetProcAddress(hDLL, "mlfAdd");
mlfAddPtr(1, sum, operand1, operand2);
}
}
However, after an exhaustive search of my system, it is clear that Matlab, the Matlab Compiler, and Matlab Compiler SDK do not install with an available "libmatrix.h" file, and without this include, the mxArray data type cannot be instantiated, and without the instantion the DLL cannot be invoked. However, the mxArray documentation is VERY sloppy and offers no help, and documentation on libmatrix.h is nonexistent.
So how can this file be completed to correctly instantiate the mxArray so that the DLL function can be correctly invoked?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!