Writing a MATLAB File from a DLL Called by LabVIEW

After testing my code, I decided to include it in the project at last. The problem is that when LabVIEW 2010 (SP1 64-bit) loads a custom DLL, it looks through the dependencies and finds that it needs tbb.dll in the end. Well, as far as I can tell, LabVIEW is using its own version of tbb.dll. And its version lacks an entry point ?throw_exception_v4@internal@tbb@@YAXW4exception_id@12@@Z

. I ran the function separately and it worked fine. It would seem that this is not an unheard of LabVIEW bug that has not been fixed.

Since this is a dependency on a third party library, I can either not use the MATLAB libraries and do everything from scratch, or I can get LabVIEW to load a working version of tbb.dll, which appears to mean copying the DLL to the Windows folder. None of these are acceptable solutions. Also, we do not have a license for Mathscript . Any ideas?

Just in case I did something wrong when I changed their example, a simplified version of my code looks like this:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include "mat.h"
#include "createMatFile.h"

export "C" int createMatFile(const char *filename, int* dataArray, int count)
{
    MATFile *pmat;
    mxArray *data;
    mwSize dims[2] = {1,1};

    //Open the file to write to
    pmat = matOpen(filename, "w");
    if (pmat == NULL) {
        printf("Error creating file %s\n", filename);
        printf("(Do you have write permission in this directory?)\n");
        return(EXIT_FAILURE);
    }

    //Convert data to double
    double* dataDouble = new double[count];

    for(int i=0; i<count; i++)
    {
        dataDouble[i] = (double)data[i];
    }

    //Populate the mxArrays
    dataArray = mxCreateDoubleMatrix(1,count,mxREAL);
    memcpy((void *)(mxGetPr(dataArray)), (void *)dataDouble, sizeof(*dataDouble)*count);

    //Put the shape struct in the .mat file
    int status = matPutVariable(pmat, "data", dataArray);
    if (status != 0) {
        printf("%s :  Error using matPutVariable on line %d\n", __FILE__, __LINE__);
        return(EXIT_FAILURE);
    } 

    //Clean up
    delete [] dataDouble;
    mxDestroyArray(dataArray);

    //Close the file to write to
    if (matClose(pmat) != 0) {
        printf("Error closing file %s\n",filename);
        return(EXIT_FAILURE);
    }

    return EXIT_SUCCESS;
}

      

The .h file is just a prototype for a function.

+3


source to share


1 answer


Since LabVIEW installs its own version of tbb.dll in the window path and loads it, the only way to fix this is to copy the new tbb.dll file to the system32 folder. This is not a good solution, so the only possible answer is:



  • Use this system hacker, which is likely to cause other problems in the future.
  • Create a hack to dynamically load the appropriate DLL into a separate process without loading anything from LabVIEW, and call the MATLAB DLL from that process and then return the value computed for the LabVIEW process. Since my program only writes data to a file, it shouldn't return anything back to LabVIEW, simplifying this choice.
  • Or, just stop using MATLAB and LabVIEW together.
+1


source







All Articles