2014-09-18 106 views
3

單獨測試我的代碼後,我決定最終將它合併到項目中。問題在於,當LabVIEW 2010(SP1,64位)加載自定義DLL時,它會逐步檢查依賴關係,最終發現它需要tbb.dll。那麼,就我所知,LabVIEW使用它自己的tbb.dll版本。其版本缺少入口點[email protected]@[email protected]@[email protected]@@Z。我分別運行該功能,並且它運行良好。 It would appear this is not an unheard of LabVIEW error which hasn't been addressed.從LabVIEW調用的DLL中編寫MATLAB文件

由於這是第三方庫的依賴關係,我可以不使用MATLAB庫,從頭開始創建,或者我可以強制LabVIEW加載tbb.dll的工作版本,這似乎意味着複製該DLL放入Windows文件夾中。這些都不是可用的解決方案。此外,我們沒有Mathscript的許可證。有任何想法嗎?

以防萬一,我做錯了什麼事,當我修改他們的榜樣,我的代碼的簡化版本如下:

#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; 
} 

.h文件是函數的只是原型。

+0

可能是x32/x64的問題? – Austin 2014-09-19 16:12:23

+0

我也這麼想過。我們使用的是64位版本的LabVIEW,以及64位版本的MATLAB庫。我的dll是爲64位體系結構而構建的。現在,因爲[無法將32位dll加載到64位進程中](http://programmers.stackexchange.com/questions/240518/accessing-a-32-bit-dll-from-a-64- bit-process)我寫了這個選項。 – Poik 2014-09-19 17:37:40

+0

嘗試使用Labview加載dll庫,手動加載你需要的tbb.dll,看看是否有效? – Austin 2014-09-19 18:48:52

回答

1

由於LabVIEW將自己的tbb.dll版本安裝到windows路徑中,並加載它,修復它的唯一方法是將新的tbb.dll複製到system32文件夾中。這不是一個好的解決方案,所以唯一可能的答案似乎是:

  • 使用此system32 hack可能會導致其他問題的道路。
  • 創建一些hack動態加載正確的DLL在一個單獨的進程中沒有從LabVIEW加載任何東西,並從該進程調用MATLAB DLL,然後返回計算值到LabVIEW進程。由於我的程序只將數據寫入文件,因此不必將任何內容返回給LabVIEW,從而簡化了這一選擇。
  • 或者只是停止使用MATLAB和LabVIEW結合使用。