cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

custom function fc

DM_10631844
11-Garnet

custom function fc

333111111

 

222

 

Greetings, I tried to create custom functions in mathcad and it asks to do so, however when I tried to create the function fc and fc1 I found an error message

----------------------------------------------

Translated the text from Spanish to English using google translate

Body - Saludos intente crar funciones personalizadas en mathcad y pude hacerlo, sin embargo cuando intente crear la funcion fc y fc1 encontre un mensaje de error

--By Community Moderation Team

----------------------------------------------

ACCEPTED SOLUTION

Accepted Solutions

There's just one problem here, the indices on the return vector/matrix are switched.  Per the Mathcad Prime documentation for LRESULT:

 

The arrays and scalars that you can pass in and out of a DLL file are always complex, and arrays are always two dimensional. You can access the real and complex parts of any scalar input value by using the ParamName->real and ParamName->imag members. Similarly, you can access the real and complex parts of any input array by using the Array->hReal and Array->hImag members. Arrays are indexed by column, then row, as opposed to the order of indices inside PTC Mathcad (by row, then column). All arrays are assumed to have two dimensions. To reference a vector, you set the first array index (column) to 0, for example:
• ArrayName->hReal[0][row], or
• ArrayName->hImag[0][row]
 
Your code is over-running the dimensions of the y matrix in the column direction.  Just swap your indexes to:
 
y->hReal[0][i] = x->real * x->real;
 
I compiled your code and it works with this fix.
 
P.S. You can always drag and drop a file as an attachment to a post.

View solution in original post

7 REPLIES 7

Hi @DM_10631844,

Thank you for your question. 

Your post appears well documented but has not yet received any response. I am replying to raise awareness. Hopefully, another community member will be able to help.

Regards,

Vivek N
Community Moderation Team.

There's just one problem here, the indices on the return vector/matrix are switched.  Per the Mathcad Prime documentation for LRESULT:

 

The arrays and scalars that you can pass in and out of a DLL file are always complex, and arrays are always two dimensional. You can access the real and complex parts of any scalar input value by using the ParamName->real and ParamName->imag members. Similarly, you can access the real and complex parts of any input array by using the Array->hReal and Array->hImag members. Arrays are indexed by column, then row, as opposed to the order of indices inside PTC Mathcad (by row, then column). All arrays are assumed to have two dimensions. To reference a vector, you set the first array index (column) to 0, for example:
• ArrayName->hReal[0][row], or
• ArrayName->hImag[0][row]
 
Your code is over-running the dimensions of the y matrix in the column direction.  Just swap your indexes to:
 
y->hReal[0][i] = x->real * x->real;
 
I compiled your code and it works with this fix.
 
P.S. You can always drag and drop a file as an attachment to a post.
JeffH1
16-Pearl
(To:JeffH1)

@DM_10631844 - Please accept the above as the answer if appropriate.

 

I've attached my version of your code basing it on the standard template provided by PTC.  I had to change the extension from ".C" to ".txt" to post it here.  you'll need to change it back to use it.  It gives the following result in Mathcad Prime:

JeffH1_0-1721485643640.png

 

 

 

JeffH1
16-Pearl
(To:JeffH1)

Let's try again.   I'll zip it.

DM_10631844_0-1721697016504.png

DM_10631844_1-1721697076198.png

It only works for visual studio command promp so it has worked for you?
Could you tell me how it would be like this please? @terryhendicott @JeffH1 

In Visual Studio IDE:

  • Make sure you are compiling to "Release" and "x64" (in the main menu).  Mathcad is 64-bit and needs a 64-bit DLL.  Mathcad also won't know what to do with the Debug information in the DLL, so make it "Release".

In the VS Project Options:

  • Set General compile type to DLL (not EXE)
  • Add C++ path location to find the MCADINCL.H file in the Custom Functions folder
  • Add Linker path location to find the mcaduser.lib file in the Custom Functions folder
  • Set the DLL Entry Point under Linker Advanced

I think that should do it.  Output DLL will be in the x64 folder of the VS project.

Thank you, perfect, first I review it and I assume your answer is valid, thank you very much, greetings 

Announcements

Top Tags