Skip to main content
6-Contributor
July 14, 2026
Solved

Need a minimal working C++ Custom Function project for Mathcad Prime (Visual Studio)

  • July 14, 2026
  • 18 replies
  • 205 views

Hello,

I am new to developing custom functions for Mathcad Prime.

I already managed to create a working custom function in C, but I still cannot understand how to do the same in C++.

To be honest, I do not understand the internal structure of Visual Studio C++ projects yet. I am learning step by step and using AI to help me understand the code and project structure.

My goal is to move large engineering calculations from Mathcad into C++ DLL libraries. I hope to use AI to help convert my Mathcad algorithms into C++, but first I need to understand how a working C++ custom function project is organized.

At the moment I cannot even create a very simple function like:

int add(int a, int b)
{
    return a + b;
}

I am not asking anyone to write my project for me.

I would simply like to have a minimal Visual Studio C++ project that builds into a DLL and is recognized by Mathcad Prime. Even a project containing only one simple function would be enough.

Once I have one working example, I believe I will be able to study it and continue developing my own functions with the help of AI.
If there is an official Visual Studio C++ sample project from PTC or a community example, I would be very grateful for a link.

Thank you very much for your time.

Best answer by terryhendicott

This actually works I tested it.  Earlier one does not.  Visual C++ 2022 solution.

You should expect this when you place resulting DLL in C:\Program Files\PTC\Mathcad Prime 11.0.0.0\Custom Functions.

 

18 replies

21-Topaz II
July 15, 2026

Here is Visual C++ solution for adding two values together.

Hope it helps

21-Topaz II
July 15, 2026

Hope this helps Visual C++ 2022 solution file.  Assumes Prime installed in default location.

21-Topaz II
July 15, 2026

This actually works I tested it.  Earlier one does not.  Visual C++ 2022 solution.

You should expect this when you place resulting DLL in C:\Program Files\PTC\Mathcad Prime 11.0.0.0\Custom Functions.

 

6-Contributor
July 15, 2026

Hi,

Thank you very much for sharing the sample project. It has helped me understand the Mathcad Prime C API much better.

Let me briefly explain what I am trying to accomplish.

I am a mechanical engineer, and I use Mathcad Prime together with Finite Element Analysis (FEA) to verify the strength and stability of engineering structures.

After completing the analytical calculations in Mathcad, I export the calculated results to DXF format, which I then use in AutoCAD and other engineering software.

My long-term goal is to build my own Mathcad DLL library containing custom engineering functions. Besides mathematical functions, I would also like to store template files (for example, empty DXF files or templates for other engineering software) directly inside the DLL. My idea is to load these templates into Mathcad, modify them by inserting the calculated results, and then export the modified template back to a plain text file such as DXF.

While working on this project, I discovered that mcadincl.h provides support for:

  • COMPLEX_SCALAR
  • COMPLEX_ARRAY
  • MCSTRING

However, I could not find any support for an array or matrix of strings.

My question is:

Is it possible for a custom DLL function to receive or return a vector (or matrix) of strings, or is this simply not supported by the Mathcad Prime C API?

For example, I would like to pass something conceptually like:
["A" "B" "C"]
 

between Mathcad Prime and my DLL.

I have searched the documentation and the sample projects but could not find any examples of working with string arrays.

Is there any supported or undocumented way to work with string arrays in a custom DLL?

Thank you very much for your time and for sharing your knowledge.

Best regards.

21-Topaz II
July 15, 2026

“I am new to developing custom functions for Mathcad Prime.”

A custom function is a C program that extends Mathcad Prime functionality.  It takes any number of parameters (no array or matrix of strings) to the C function from Prime and returns one result to Mathcad Prime.  Custom Functions have their own section in the help documentation with several examples.  Note: You can use the DLL interface specifications for creating customized external functions that work with PTC Mathcad only for your personal or internal business use. These specifications may not be used for creating external functions for commercial resale without prior written consent from PTC. See PTC Customer Agreement for details.

Mathcad Prime Application Programming Interface (API) is a method to activate the Prime application, open, activate, calculate and close worksheets and exchange data from predefined input and output regions in Prime worksheet to the language used for the API programming.  Many languages are available C++, C#, VB etc.  API has its own section in the help documentation separate to the custom functions section.    Data can be received by a C++ application, perform calculations in C++ and return outputs to Prime.  Prime can receive data from C++ perform Prime Calculations and send data back to C++ using the predefined input and output regions.  User has to do the synchronization for this to happen.

“My goal is to move large engineering calculations from Mathcad into C++ DLL libraries”.  “I hope to use AI to help convert my Mathcad algorithms into C++”

Neither the custom functions nor API can convert Prime calculations to C++, but do not give up hope.

I have successfully this week using chatGPT converted eighteen large partial differential symbolic equation results from Prime equations to C++.  Also for FEA work.  I want them in C++ for speed and to handle larger matrices than Prime can handle.  Prime is great for the theory.

Prime files are simply a zipped collection of internal files.  One of those internal files called worksheet.xml contains regions that each represent a single Prime equation.  Communication to chatGPT was facilitated by exchanging the individual xml text of the equation regions.  chatGPT has learnt the syntax of these text regions and can convert them to C++.  It took three days for the translation as several attempts needed to be made to convert and properly and methodically test the C++ results.  Manual intervention was needed to finalise all eighteen as the conversion by chatGPT was not entirely correct.  Not everything in Prime is translatable like this to C++, An integration equation for instance.

chatGPT has learnt the internal Prime syntax from work I did a few weeks ago.  Refer to an earlier post https://community.ptc.com/mathcad-7/primeconnect-c-prime-c-174812.

Cheers
Terry

6-Contributor
July 15, 2026

Hi Terry,

Thank you very much for your detailed explanation.

I understand now that arrays or matrices of strings are currently not supported by the Custom Function API.

I hope that in future versions of Mathcad Prime the developers will consider adding more built-in text processing capabilities.

For engineering applications, especially when working with text-based formats such as DXF, STEP, G-code, or other CAD/CAM files, this would be extremely useful.

One common problem is that values such as:
2E04
are automatically interpreted as the number 20000, even when they should remain plain text. This makes it difficult to process many engineering file formats correctly.

Another limitation is that Mathcad always treats strings as quoted text. When exporting to a text file, it would be very useful to have a built-in option to write plain text without quotation marks.

I know there are community-developed Mathcad worksheets that solve many of these problems by reading files as binary data and then converting them back into strings. These are excellent solutions, and I appreciate the work that has gone into them.

However, from a usability point of view, I would still prefer to have these capabilities available as standard built-in functions. It would make worksheets much easier to share with other engineers, without having to distribute additional worksheets containing custom helper functions.

Thank you again for all your work and for helping the Mathcad community.

Best regards.

21-Topaz II
July 15, 2026

https://community.ptc.com/mathcad-7/primeconnect-c-prime-c-174812.

You may be more interested in this post when you know it can create using C++ a mixed Prime matrix of strings and numbers for DXF creation.

		Worksheet ws;


ws.Define(L"Circle",Matrix(9, 1, std::vector<Expr>{
Str(L"AcDbCircle"),
Real(10),Real(2026.478),
Real(20),Real(1587.236),
Real(30),Real(0.0),
Real(40),Real(217.893)
}));

Cheers

Terry

13-Aquamarine
July 17, 2026

The Universal Way: https://github.com/ViacheslavMezentsev/NetEFI
 

NetEFI Framework for Mathcad

 

This framework allows you to create user-defined functions for Mathcad 15 and Mathcad Prime using any .NET language (C#, VB.NET, F#, C++/CLI). It removes the need to write C++ code by providing a simple, attribute-based API, allowing you to focus on your function's logic in a familiar, strongly-typed managed environment.


You can see how the project itself is designed. The project's structure allows it to be compiled for all versions of Mathcad, starting with version 15.

 

 

21-Topaz II
July 17, 2026

Hi 

Followed the instructions on NetEFI and used following code:  Does not know what a Complex is? How do I get Complex types?

 

using System.Numerics;
using NetEFI.Runtime;
using NetEFI.Functions;

[Computable("cs_sum", "a, b", "Calculates the sum of two complex numbers")]
public class MySumFunction : CustomFunction<Complex, Complex, Complex>
{
    public override Complex Execute(Complex a, Complex b, Context context)
    {
        return a + b;
    }
}

13-Aquamarine
July 17, 2026

You need to use AI. He will tell you what is missing and why. Complex - .Net Framework data type.

Try these examples first:

https://github.com/ViacheslavMezentsev/NetEFI/tree/master/samples/csharp/cstest
 


You can also use VSCode

 

21-Topaz II
July 18, 2026

Got sample working for Mathcad 15 following Quick Start Guide.

:Could not and have tried multiple times to get it working in Prime 11:

Can you please provide a working Visual Studio solution for PTC Mathcad Prime?

Cheers

Terry

21-Topaz II
July 18, 2026

Hi,

Have compiled the sample from the gitHub carefully.  Get seven compiled items as expected when compiling for x64 architecture to suit Prime.  But transferring the DLL’s as instructed to the Prime Custom Functions directory does not get a positive result.  Please just one complex sum in c# please.

Cheers

Terry

13-Aquamarine
July 18, 2026

The releases page includes ready-to-use builds you can try before building your own. The path to the log file is also provided in case of any issues.


 

21-Topaz II
July 18, 2026

Hi,

Thank you for this simpler way of writing custom functions.  Have got a successful compile and examples are running in Prime 11.  Thank you so much.

13-Aquamarine
July 18, 2026

If problems arise, you need to look at the log file:

 C:\Users\User\AppData\Roaming\Mathsoft\Mathcad\netefi.log
 

It contains information about the launch

18.07.2026 12:27:56 [INFO ] .Net: 4.0.30319.42000

18.07.2026 12:27:56 [INFO ] netefi, 64-bit release version 0.2.7694.43189, 24-янв-2021 23:59:38

...

18.07.2026 12:27:56 [INFO ] netefi - [ cmd ] return string

18.07.2026 12:27:56 [INFO ] netefi.dll: 1 function(s) loaded.

...

18.07.2026 12:30:50 [INFO ] OS: Microsoft Windows NT 10.0.26200.0, 64-bit: True

18.07.2026 12:30:50 [INFO ] Current Culture: ru-RU

18.07.2026 12:30:50 [INFO ] Running as Administrator: False

18.07.2026 12:30:50 [INFO ] PTC Mathcad Prime version 11.0.0.0, Copyright © PTC Inc. All rights reserved.

18.07.2026 12:30:50 [INFO ] .Net: 4.0.30319.42000

18.07.2026 12:30:50 [INFO ] NetEFI: 64-bit release version 0.5.9583.24855 (28-мар-2026 13:48:30)

18.07.2026 12:30:50 [INFO ] Starting assembly scan for CustomFunction types...

18.07.2026 12:30:50 [INFO ] Assembly loaded: C:\Program Files\PTC\Mathcad Prime 11.0.0.0\Custom Functions\NetEFI.Abstractions.dll

18.07.2026 12:30:50 [INFO ] Allocated 560 bytes for 14 function trampolines.

18.07.2026 12:30:50 [INFO ] csdec - [ m ] Decodes a vector of packed integers into a 2-bit grayscale matrix.

18.07.2026 12:30:50 [INFO ] csrfile - [ filePath ] Returns the content of a specified text file.

18.07.2026 12:30:50 [INFO ] csenc - [ m ] Encodes a grayscale matrix into a vector of packed integers.

18.07.2026 12:30:50 [INFO ] csmix - [ m, direction ] Shuffles the elements of a matrix using a pseudo-random generator.

18.07.2026 12:30:50 [INFO ] cserror - [ n ] Throws a custom error specified by its index n.

18.07.2026 12:30:50 [INFO ] cssum - [ a, b ] Calculates the complex sum of two scalars.

18.07.2026 12:30:50 [INFO ] cstable - [ seed ] Generates a frequency table of pseudo-random numbers.

18.07.2026 12:30:50 [INFO ] cstest - [ cmd ] A utility function to inspect the C# test assembly.

18.07.2026 12:30:50 [INFO ] cstest1 - [ x ] Returns the complex scalar 2 * x.

18.07.2026 12:30:50 [INFO ] cstest2 - [ separator, v ] Returns a string representation of a vector with a separator.

18.07.2026 12:30:50 [INFO ] cstest3 - [ n, m ] Returns an n x m matrix of complex numbers.

18.07.2026 12:30:50 [INFO ] csecho - [ s ] Returns the input string.

18.07.2026 12:30:50 [INFO ] cstranspose - [ X ] Returns the transpose of matrix X.

18.07.2026 12:30:50 [INFO ] cstest.dll: 13 function(s) loaded.

18.07.2026 12:30:50 [INFO ] netefi - [ cmd ] NetEFI host command interface. Returns help string by default.

18.07.2026 12:30:50 [INFO ] NetEFI.dll: 1 function(s) loaded.

18.07.2026 12:30:51 [INFO ] Assembly not found: C:\Program Files\PTC\Mathcad Prime 11.0.0.0\Custom Functions\Ptc.Core.XmlSerializers.dll