To create your own Microsoft Visual ... - Home - PTC …
The download on Mathcad DLLsMore and more engineers are coming to the table with programming skills. Bravo!! But many draw the line at DLLs. They are a mystery, dark magic DLLs are just another mechanism to distribute your code.The concept of DLLs has been around for many years. VMS, UNIX, Linux all have had their variation on this common, dynamically shared library theme: VMS had *.OLB files, UNIX and Linux have *.so files.DLL stands for Dynamically Linked Library. This is different from statically linked libraries.The idea is to be able to provide an application developer with routines he/she can leverage in the application without having to distribute the source code to said developer. A DLL is a binary file, much like an *.exe, however it cannot run standalone like an *.exe. It needs to be linked into the main application and then called by the application. Updates to the application can be made by simply installing newer versions of the DLLs.Mathcad provides a mechanism for end users to call DLLs thru the Mathcad interface. A DLL can be one function or as in the case of the Prode.DLL (Prode Physical Properties) there are 225 functions which the user can call. In Mathcad Prime 3.0 we call user DLLs Custom Functions.Mathcad provides a number of examples showing developers the MCADUSER.LIB functions necessary to turn C code into a Mathcad Custom Functions. These examples are terrific because they are simple and complete. They demonstrate programmatically 1.) How to get data into your Custom Functions function, 2.) How to return data from your Custom Functions function to the Mathcad worksheet and also 3.) How to register your Custom Functions so Mathcad sees it.Those three areas of interest represent what is known in programming circles as the wrapper. What does Mathcad require to “wrap” my code into a usable Mathcad Custom Functions?Installed with Mathcad Prime 3.0 under installdir\Custom functions are a number of plexSum .c contains all 3 areas of interest in one file. It not only defines what is passed in to and what is passed out of the Customer Function, it also defines its DLL entry point.Mutliply.c is of the same ilk. It contains all 3 areas of interest in 3 code segment.The USERPACK example steps up the interest level. This example separates the computational code from the DLL code. REALSUM.c and TRNSPOSE.c house the computational code along with memory allocation calls for data returning to Mathcad’s worksheet. USERPACK.c creates the DLL entry point and registers both REALSUM and TRNSPOSE functions. This is closer to real world. No need to repeat the DLL entry point code for every module. Think about the Prode example referenced earlier. Copy all that code 225 times? Imagine if you made a mistake, 225 files to edit!I’d like to make this even simpler and much more real world. The Mathcad online help instructions have you compile and link by command line, a subset of documentation is shown below. Now while this is accurate it is not how developers really work today. CommandDescriptioncl —c —I..\ —DWIN32 CMPLXSUM.CGenerates the cmplxsum.obj file in the current folder. link -out:..\cmplxsum.dll -dll -entry:"DllEntryPoint" cmplxsum.obj ..\MCADUSER.LIBGenerates the cmplxsum.dll file in the Custom Functions folder.For most developers on the Windows platform we are using Microsoft Visual Studio and leverage their awesome website for any help, examples, tutorial etc. A combination of Microsoft tools and Mathcad examples are the best recipe for getting you building Mathcad Custom Functions in minutes.Specifically I am recommending you use Microsoft Visual Studio to create MVS Solution which builds a DLL. With this in place you can easily edit, compile, and run your DLL in a professional development environment. When you complete building your Custom Function you simply copy it to the Custom Functions directory, start Mathcad Prime 3.0 and call your function.Along with this blog I have included the USERPACK example as a Visual Studio Solution. Along with REALSUM and TRNSPOSE I have added a new function: gmtime, which when called with you time zone from GMT (east coast = -4) it will return the date and time for your TZ. Below is the code. You can see it is a simple modification to REALSUM or TRNSPOSE. I then simply add gmtime twice to USERPACK.C. You can see where. So this code is the “wrapper” for my date function and USERPACK registers it in the USERPACK.dll, which I then copy to installdir\Custom Functions.#include "StdAfx.h"#include "mcadincl.h"#include <time.h> LRESULT gmdateFunction(LPCOMPLEXARRAY datevec, LPCCOMPLEXSCALAR TZ ); FUNCTIONINFO gmdate = { "gmdate", // Name by which Mathcad will recognize the function "TZ", // Date will be called as Date(TZ) "returns vector of time date info", // description of Date(TZ) (LPCFUNCTION)gmdateFunction, // pointer to the executable codeCOMPLEX_ARRAY, // the return type is vector 1, // the function takes on 1 arguments {COMPLEX_SCALAR} // one argument is a complex scalar }; LRESULT gmdateFunction(LPCOMPLEXARRAY datevec, LPCCOMPLEXSCALAR TZ ) {time_t rawtime;struct tm * ptm; MathcadArrayAllocate ( datevec, // allocate space for Y 5, // with cols 1, // and X rows 1, // allocate the real part if X has a real part 0 // allocate the imaginary part if X has // an imaginary part ); time (&rawtime); ptm = gmtime(&rawtime); datevec->hReal[0][0] = (int)(ptm->tm_hour+TZ->real)%24; datevec->hReal[0][1] = ptm->tm_min; datevec->hReal[0][2] = ptm->tm_mday; datevec->hReal[0][3] = ptm->tm_mon; datevec->hReal[0][4] = (1900+ptm->tm_year); return 0; // return 0 to indicate there was no error } To create your own Microsoft Visual Studio DLL solution for MathcadOf course you can modify the included example. But of you want to start from scratch follow these instructions.========================================================================Using Visual Studio 2010 to build Custom Functions in Mathcad Prime 3.0========================================================================In Dev Studio 2010 build a Windows Console app and on the property page select DLL as project type 2. Set up path for external libraries and headers The path settings will need to be in project property sheets per project. Go to "Project" and select "Properties", find "Configuration Properties", and then "VC++ Directories". 2.1 If you are building on 64-bit Windows, find the "Platform" dropdown and select "x64". 2.2 Add the header path to the "Include Directories" setting. C:\Program Files\PTC\Mathcad Prime 3.0\Custom Functions 2.3 Add the library path to the "Library Directories" setting. C:\Program Files\PTC\Mathcad Prime 3.0\Custom Functions 2.4 Select Linker->Input and beginning with the "Additional Dependencies" line, enter the library names. Enter: mcaduser.lib 3. Copy target DLL to C:\Program Files\PTC\Mathcad Prime 3.0\Custom FunctionsWe are happy to mention the 2012 free version of Microsoft Visual Studio .. called Express.. works with Mathcad Prime 3.0 Custom Functions ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- create your own company website
- create your own mmd
- create your own mmd character
- how to sell your own home yourself
- create your own starbucks drink
- create your own poem
- create your own business website
- create your own company game
- create your own website for free
- create your own website free and easy
- create your own website with free domain
- create your own amortization schedule