libmatrix.h library for C/C++ DLL importing

조회 수: 2 (최근 30일)
Joshua Baldwin
Joshua Baldwin 2017년 9월 27일
편집: Joshua Baldwin 2017년 9월 27일
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개)

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by