Simplicty and flexibility!

How to create CDFs for use in DE8/DG3

This is how you create your own CDFs using Visual Studio 2013. I selected to use this version because any one can get a full version for free as long as you register with MicroSoft. You should be able to recreate this in any version of Visual Studio in almost the same way as described here. Not much has changed in creating Windows DLLs in the last 20 years. You probably can do the same using other compilers as MinWin GCC and Embarcadero, but that is outside the scope of this document.

How to create a CDF using Visual Studio 2013

Start Visual Studio 2013

Create a new project

Select: Templates->Visual C++->Win32->Win32 Project

Give the project a proper name and a directory where you store the project

Then you run the Win32 Application wizard, just skip the first screen by pressing next and then pay attention to the next screen.

Change from Windows application to DLL, check Export symbols and leave the rest

Now you have got a new project where you can write your code. The are some code already, if you did not select an empty project. We will not keep much of this, but it saves some typing to leave it in. It also illustrate what is needed to create a dll and export functions, classes and variables. We are only interested in the functions for CDFs, so we remove the rest and do an important changes to make the CDF work from DfW and DG3.

The new examplecdf.h file

// The following ifdef block is the standard way of creating macros which make exporting  
// from a DLL simpler. All files within this DLL are compiled with the EXAMPLECDF_EXPORTS 
// symbol defined on the command line. This symbol should not be defined on any project 
// that uses this DLL. This way any other project whose source files include this file see  
// EXAMPLECDF_API functions as being imported from a DLL, whereas this DLL sees symbols 
// defined with this macro as being exported. 
#ifdef EXAMPLECDF_EXPORTS 
#define EXAMPLECDF_API extern "C" __declspec(dllexport) 
#else 
#define EXAMPLECDF_API __declspec(dllimport) 
#endif 

EXAMPLECDF_API int fnexamplecdf(void); 

The new examplecdf.cpp file

// examplecdf.cpp : Defines the exported functions for the DLL application. 
// 

#include "stdafx.h" 
#include "examplecdf.h" 

// This is an example of an exported function. 

EXAMPLECDF_API int fnexamplecdf(void) 
{
 	return 42;
}

The changes worth noting is #define EXAMPLECDF_API __declspec(dllexport) is now #define EXAMPLECDF_API extern "C" __declspec(dllexport). The added extern "C" is the code that makes DfW and DG3 able to recognize the function names. If not the names will be full name with parameters and calling convention. This is not recodnozed by the current version of DfW and DG3.

Install the new CDF in DfW

To use your newly created CDF in DfW, you need to copy the dll file (in this example the examplecdf.dll) from you release area (Ex. E:\Projects\experiments\examplecdf\examplecdf\Release) to your application folder or DfW installation folder pluss CDFLIBS folder contained inside the DfW folder. This DfW installation folder are usually called "C:\Program Files (x86)\DataEase\DataEase x.y\CDFLIBS\" where x is the major version and y is the minor version of the software at the point of first installation. So if you have a fairly new installation it should be "C:\Program Files (x86)\DataEase\DataEase 8.5\CDFLIBS\". Then you need to add en entry in your Custom Function table.

And then to test that it works, just add a button on your page, use Execute Function/Derivation and add this formula:

Message(concat("The meaning of life is: ",fnexamplecdf()),"Important",0,0,0)

Then have made your first CDF that you can use in your applications.

Install the new CDF in DG3

To use your newly created CDF in DG3, you need to copy the dll file (in this example the examplecdf.dll) from you release area (Ex. E:\Projects\experiments\examplecdf\examplecdf\Release) to your application folder or DG3 installation folder pluss DE4Web\Prism\cdflibs\ . This DG3 installation folder are usually called "C:\Program Files (x86)\DG3". So the full path to CFGLIBS should be "C:\Program Files (x86)\DG3\DE4Web\Prism\cdflibs\". Then you need to add en entry in your Custom Function table.

Make a test DQL to test funtion

That's it you have a result

Reference documentation and tools

Visual Studio download for downloading Community 2013 with Update 4

Exporting C++ Functions for Use in C-Language Executables

DLL Export viewer that is easy to use and understand

Published: 29/05/15 - 15:03:10 (Amanda Higgins)

Last changed: 10/06/15 - 10:33:03 (Bjørn Helge Kjøsnes)

Related Articles

How to create CDFs for use in DE8/DG3