Skip to main content
1-Visitor
August 20, 2021
Solved

mathcad DLL cannot run twice with different parameter

  • August 20, 2021
  • 1 reply
  • 5644 views

Hi, I build a DLL function and run well in visual studio debug and got the result as i want.

But mathcad load into this dll and try to run this dll twice with different parameter.

As below pictures,

first, i load this dll twice with different parameter (INP_g_pow_acc) & (INP_g_pow_acc1), but got same result (this result is correspond to INP_g_pow_acc)

second, i exchange the parameter (INP_g_pow_acc & INP_g_pow_acc1), also got same result (this result is correspond to INP_g_pow_acc1)

Seem mathcad just load this dll once, how can mathcad run dll twice with different parameter??

Very thanks for your kindly support.  

 

 

圖片1.png圖片2.png 

Best answer by LucMeekes

In the top of your source code you (globally) define two arrays:

      float INP_g_pow_acc[224];

      float INP_g_theta_1[224];

The definition of your Mathcad function has parameters (which should behave as local variables within the function) with the same name:

     LPCCOMPLEXARRAY INP_g_pow_acc

     LPCCOMPLEXARRAY INP_g_theta_1

Now the compiler should be capable of discriminating between the global and the local variables with the same name. But, considering that these two parameters appear to be involved in what goes wrong in your double calling of the function from within Mathcad, I would comment out the global definition of the arrays, and see what happens.

 

I hope this solves your problem.

 

Other notes:

- The function MathcadArrayAllocate() is used to allocate storage for the result array Product. The function MathcadArrayFree() is called only when the function is interrupted by the user, and releases the memory set aside for the result (that isn't going to be delivered in that case). Both functions are used OK as far as I can tell.

- You have a lot of magic numbers (constants) in your code. What if you call the function from within Mathcad with as first argument an array of not 694, but 311, or 1250 elements. You could (should ?) make a lot of the constants dependent on the size(s) of the array(s) supplied to the function. You now only check that the arrays don't contain imaginary parts, but since you do not use any of that, this check can be omitted. If you supply the arrays with complex data, nothing of it is used, you should get the same result. If you stick with the fixed array sizes, it makes more sense to check that the arrays supplied to the function are as large as you expect them to be.

 

Success!
Luc

1 reply

1-Visitor
August 20, 2021

I am a newer to use mathcad. could someone can support or give me a keyword or hint? 

it is confused me for a long time.

thanks you for your kindly support.

21-Topaz II
August 21, 2021

Hi,

The kronecker function is an example DLL in the Mathcad distribution.  See Help | Developer's Reference

Capture3.JPG

DLL can be found in the following directory.

Capture.JPG

Possible to use different parameters at each call.

Capture2.JPG

Check your DLL. The double use of one DLL is illustrated at the top of the enclosed file.

Cheers

Terry

21-Topaz II
August 21, 2021

Hi,

I get different results when you change the input parameter.

Capture.JPG