Creating a custom function
To create your own functions, a C or C++ development tool is required, or the Java Native Interface (JNI) if you are working in a Java environment.
Procedure
- From
a component rule in the Type Designer or from a map rule in the Map
Designer, right-click and select the Insert Function option.
(Additionally in the Map Designer, if you are not in a map rule, you can create a new function by selecting.)
- From the Insert Function window, select Design.
The Custom Function Modules window is displayed.
- In the Path field, enter the path
of where to create the external library. This should always be in the install_dir/function_libs directory.
- In the Name field, enter a name for the library.
- Click Add to add a function to the
library. The Function Specifics window is displayed.
- In the Name field, enter a name for the function.
- For Return Type, select the function
return type from the drop-down list. You can select up to four function parameters from the respective drop-down list. Choices include Boolean, date, number, text, time, and byte stream.
- In the space provided, enter a description for your function.
This information will be displayed in the Insert Function window of both Designers.
- Click OK to validate the selected parameters and close the Function Specifics window.
- Click Generate. The Designer generates a collection of operating system specific makefiles and definition files that provide the framework for the function you are creating.
-
Go to the install_dir/function_libs directory to view
the results.
As a result of the generation process, framework files are created for each operating system that HCL OneTest™ Data supports. You can find the operating system-specific makefiles and definition files in the install_dir/function_libs/your_new_lib directory.
- Now you must modify the framework that was generated by
the Designer. The following functions with the parameter information that you selected were exported to the .c file:
- GetFunctionCount
- GetFunctionName
- GetInputParameter
- GetReturnType
- GetParameterCount
- GetFunctionDesc
To complete the new function, open the .c file and add your programming code for the applicable function or functions provided.
Use the .c file to build your dynamic link library (DLL) and then place the DLL in the install_dir/function_libs/your_new_lib directory. (All custom designed libraries and functions must be placed in the install_dir/function_libs directory.)
The new library name is listed under Category in the Insert Function window, and the new function that you created is placed in the list of functions and will remain available for future use from both the Type Designer and Map Designer applications.
Example
void ConvertToBytes(double returnValue, LPEXITPARAM lpep)
{
double value = 0.0;
int decimal = 2, sign = 0, j = 0, k = 0;
char byString[100];
char* lpbyData = _fcvt(returnValue, 7, &decimal, &sign );
memset(byString, 0, sizeof(byString));
if (sign)
byString[j++] = '-';
if (decimal <= 0)
{
byString[j++] = '0';
byString[j++] = '.';
while (decimal != 0)
{
byString[j++] = '0'; decimal++;
}
}
else if (decimal > 0)
{
while (decimal != 0)
{
byString[j++] = lpbyData[k++]; decimal--;
}
byString[j++] = '.';
}
while (lpbyData[k]) byString[j++] = lpbyData[k++];
byString[j] = '\0';
if (NULL == (lpep->lpDataFromApp = GlobalAllocPtr
(GHND, j + 1)))
{
lpep->nReturn = -1;
lstrcpy(lpep->szErrMsg, "Memory allocation failed in Alternate");
return;
}
memcpy(lpep->lpDataFromApp, byString, j);
lpep->dwFromLen = j;
lpep->lpDataFromApp[j++] = '\0';
}
void CALLBACK EXPORT SIN(LPEXITPARAM lpep)
{
double value = 0.0;
double returnValue = 0.0;
LPEXITPARAMEXTENDED lpExtended = NULL;
if (lpep->dwSize != sizeof(EXITPARAM))
{
return;
}
lpExtended = (LPEXITPARAMEXTENDED)lpep->lpv;
value = atof(lpExtended->lpFirstInputParameter);
returnValue = sin(value);
ConvertToBytes(returnValue, lpep);
lpep->wCleanupAction = GetReturnType("SIN");
lstrcpy(lpep->szErrMsg, "SIN function was successful");
return;
}