10-29-2009 01:20 PM
Hi there,
I've created a dll in Labview that performs a calculation. It takes 2 arrays as inputs and fill an array as output. Pretty simple. I tested that I can call it from a LV project so I know the dll works.
So now I want to call it from a CVI program. So I followed the instructions (I'm not a CVI programmer, I'm a wire guy) and created a CVI program, included the .lib, .dll and .h files correctly. In fact, I moved them into the CVI directory to get it to compile. So it builds and runs without errors or warnings.
To test it I stuff data into the input variables that I know works and execute the program. My problem is that the output array is unchanged after the dll executes (as viewed in th ewatch window). Again the program executes just fine, the dll just doesn't seem to do anything - output array all zeroes. So I forced the output array to something to see if at least the dll modifies the data. Nope. Just passes the stuff through.
The only strange thing I noticed: I had to comment out "include extcode.h" in my .h file. Otherwise the build generates several errors. It builds fine without it.
Thanks for any help,
Tom
10-30-2009 04:52 AM
Can you post the relevant section of code, showing the definition of the parameters as well as the actual dll function call?
JR
10-30-2009 02:08 PM
Hi JR-
This section is in main (up above I define len,len2and len3 as constants = to the array size):
ETerms2P[0] = -0.06190923;
ETerms2P[1] = 0.02185894;
ETerms2P[2] = 0.04755964;
ETerms2P[3] = -0.02151719;
ETerms2P[4] = 0.35017347;
ETerms2P[5] = 0.66006729;
ETerms2P[6] = -0.01077147;
ETerms2P[7] = 0.10337812;
ETerms2P[8] = -0.09141181;
ETerms2P[9] = 0.75544394;
ETerms2P[10] = 0.00000854;
ETerms2P[11] = -0.00009545;
ETerms2P[12] = -0.02735079;
ETerms2P[13] = -0.00357339;
ETerms2P[14] = 0.08486504;
ETerms2P[15] = 0.02423677;
ETerms2P[16] = -0.52128575;
ETerms2P[17] = 0.58163639;
ETerms2P[18] = 0.08198126;
ETerms2P[19] = 0.11637826;
ETerms2P[20] = -0.09324849;
ETerms2P[21] = 0.74176752;
ETerms2P[22] = -0.00013321;
ETerms2P[23] = 0.00002370;
SParmUncorr[0] = 0.35979586;
SParmUncorr[1] = 139.92630000;
SParmUncorr[2] = 2.96377524;
SParmUncorr[3] = 169.67290000;
SParmUncorr[4] = 0.08037390;
SParmUncorr[5] = 80.13310000;
SParmUncorr[6] = 0.33094551;
SParmUncorr[7] = 240.34550000;
SParmCorr[0] = 1.0;
SParmCorr[1] = 2.0;
SParmCorr[2] = 3.0;
SParmCorr[3] = 4.0;
SParmCorr[4] = 5.0;
SParmCorr[5] = 6.0;
SParmCorr[6] = 7.0;
SParmCorr[7] = 8.0;
CalcSparms1(SParmUncorr,ETerms2P,SParmCorr,len,len2,len3); //this is the dll call
Here is the .h file (generated from LV):
//#include "extcode.h"
#pragma pack(push)
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
void __cdecl CalcSparms1(double MeasuredSparms[], double Eterms[],
double CorrectedSparms[], int len, int len2, int len3);
long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
11-02-2009 04:15 AM
I can't see any obvious problem with your section of code. With a wholly CVI project, my next suggestion would be to run a debug version of the dll, with breakpoints at strategic points inside it so you can see how the data is handled - or not, as it seems in your case! I have no knowledge of LabView, but I imagine that similar debug facilities must exist.
(If it turns out you are actually running the program with the wrong build of dll, you wouldn't be the first programmer to make that mistake...)
JR