<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Prime 3.0 Custom Functions (string arguments) in Mathcad</title>
    <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364978#M142923</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a user function for Mathcad 15 that works great (in Mathcad 15). I'm attempting to build that .dll for Mathcad Prime 3.0. After compiling the code (linking the mcaduser.lib that is distributed with Mathcad Prime 3.0), all the custom functions defined in my .dll work fine in Mathcad Prime 3.0, except those which return a string type value. Any function which returns a string will crash Mathcad Prime 3.0 when the function is called. Even the most simple test cases, such as the following function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Segoe UI','sans-serif'; color: #3b3838;"&gt;LRESULT testFunction(LPMCSTRING ParamValue, LPCMCSTRING ParamName)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Segoe UI','sans-serif'; color: #3b3838;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Segoe UI','sans-serif'; color: #3b3838;"&gt; ParamValue-&amp;gt;str = "foo";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Segoe UI','sans-serif'; color: #3b3838;"&gt; return 0; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Segoe UI','sans-serif'; color: #3b3838;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;will crash Prime 3.0 when invoked in a worksheet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone else experience this issue? Thanks for the feedback!&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 May 2018 16:43:22 GMT</pubDate>
    <dc:creator>spolak</dc:creator>
    <dc:date>2018-05-03T16:43:22Z</dc:date>
    <item>
      <title>Prime 3.0 Custom Functions (string arguments)</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364978#M142923</link>
      <description>I have a user function for Mathcad 15 that works great (in Mathcad 15). I'm attempting to build that .dll for Mathcad Prime 3.0. After compiling the code (linking the mcaduser.lib that is distributed with Mathcad Prime 3.0), all the custom functions defined in my .dll work fine</description>
      <pubDate>Thu, 03 May 2018 16:43:22 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364978#M142923</guid>
      <dc:creator>spolak</dc:creator>
      <dc:date>2018-05-03T16:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Prime 3.0 Custom Functions (string arguments)</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364979#M142924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By the way, the custom/user function I'm trying to build is a wrapper for CoolProp, which is an open-source library of thermophysical fluid properties, including humid air (water/steam). The user function I compiled for Mathcad 15 wraps the CoolProp library quite well. I've only implemented a few of the top level functions, but enough to sufficiently extract all properties for all the fluids in the CoolProp library. CoolProp is open-source, and so is the Mathcad wrapper for it. Here's a link to the Mathcad wrapper:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="loading vt-p" href="http://sourceforge.net/projects/coolprop/files/CoolProp/4.0.0beta/MathCAD/"&gt;http://sourceforge.net/projects/coolprop/files/CoolProp/4.0.0beta/MathCAD/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I just need to figure out these "nuances" of Prime 3.0 that are preventing me from building the CoolProp wrapper...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Nov 2013 16:36:18 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364979#M142924</guid>
      <dc:creator>spolak</dc:creator>
      <dc:date>2013-11-22T16:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Prime 3.0 Custom Functions (string arguments)</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364980#M142925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;R&amp;amp;D has been informed of this issue. Thank you for bringing it to our attention!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Nov 2013 02:27:42 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364980#M142925</guid>
      <dc:creator>RogerYeh</dc:creator>
      <dc:date>2013-11-23T02:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Prime 3.0 Custom Functions (string arguments)</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364981#M142926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Scott,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope the failure is not due to missing a call to MathcadAllocate, to obtain storage for the string...&lt;/P&gt;&lt;P&gt;{Don't know if allocation for storage of strings and arrays is required in Prime as it is in Mathcad.}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Success!&lt;BR /&gt;Luc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Nov 2013 12:30:23 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364981#M142926</guid>
      <dc:creator>LucMeekes</dc:creator>
      <dc:date>2013-11-24T12:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Prime 3.0 Custom Functions (string arguments)</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364982#M142927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Luc&lt;/P&gt;&lt;P&gt;You are correct, nice catch . Our QA/Engineering team suggests replacing the call to "new"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas; color: #0000ff;"&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt; &lt;SPAN style="font-size: 10pt; font-family: Consolas; color: #0000ff;"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;char&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; * c = MathcadAllocate(s.size()+1); &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas; color: #008000;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas; color: #008000;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas; color: #008000;"&gt;// creat a c-string (pointer) c with the same size as s&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Consolas;"&gt;In your &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;GetCoolPropsParamMathcad&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;This will protect your code across DLL boundaries.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;John&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Nov 2013 01:32:43 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364982#M142927</guid>
      <dc:creator>jsheehan</dc:creator>
      <dc:date>2013-11-25T01:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Prime 3.0 Custom Functions (string arguments)</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364983#M142928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Luc, thanks for the tip - you were absolutely correct. I've only ever used the MathcadAllocate functions for array objects, not for strings. It makes perfect sense though. Thanks again!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Nov 2013 15:45:41 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364983#M142928</guid>
      <dc:creator>spolak</dc:creator>
      <dc:date>2013-11-26T15:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Prime 3.0 Custom Functions (string arguments)</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364984#M142929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;just to develop a little more this subject, this is what works for me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// -----------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// File: test_string_return.cpp&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// test for a function that returns a string&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#include "stdafx.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#include "mcadincl.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#include &amp;lt;string&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;using namespace std;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LRESULT test_string_return_Function( LPMCSTRING ParamValue, LPCMCSTRING ParamName ); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LRESULT test_string_return_Function( LPMCSTRING ParamValue, LPCMCSTRING ParamName )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN&gt; // see: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://stackoverflow.com/questions/347949/convert-stdstring-to-const-char-or-char" target="_blank"&gt;http://stackoverflow.com/questions/347949/convert-stdstring-to-const-char-or-char&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; string str_val = "foox";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; char *cstr_val = MathcadAllocate(str_val.size() + 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; std::copy(str_val.begin(), str_val.end(), cstr_val);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; cstr_val[str_val.size()] = '\0';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; ParamValue-&amp;gt;str = cstr_val;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; // normal return&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; return 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// fill out a FUNCTIONINFO structure with&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// the information needed for registering the&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// function with Mathcad&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;FUNCTIONINFO test_string_return = &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// Name by which mathcad will recognize the function&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;"test_string_return", &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// description of "test_string_return_Function" parameters to be used&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// by the Insert Function dialog box&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;"string-value", &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// description of the function for the Insert Function dialog box &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;"test: pass a string and receive a string as output", &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// pointer to the executible code&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;(LPCFUNCTION)test_string_return_Function, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// type of returned object&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;STRING,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// number of input parameters (not including the returned object)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// test_string_return_Function( value )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;1,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// types of input parameters&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{STRING} &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// -----------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;This is needed, for example, when one wants to read the attribute of a dataset in an HDF file. In that case the string, which is the attribute value, has to be returned to Mathcad.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Agostino&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Dec 2013 12:07:22 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Prime-3-0-Custom-Functions-string-arguments/m-p/364984#M142929</guid>
      <dc:creator>agodemar</dc:creator>
      <dc:date>2013-12-06T12:07:22Z</dc:date>
    </item>
  </channel>
</rss>

