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.
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;
}
At run time, all custom designed libraries and functions that your maps use
must be in the <install_dir>/function_libs
directory. When you deploy a map that uses a custom function to a remote host, the library is
not transferred. Therefore you must manually copy the custom function library to the
<install_dir>/function_libs directory on the remote host.
From a component rule in the Type Designer or from a map rule in the Map Designer, right-click and select the Insert Functions option. The new custom functions library appears as a separate category in the Functions window displayed in the Designers. Drag and Drop the new custom function in the component rule in the Type Designer or map rule in the Map Designer.
Custom functions follow the calling convention:
library_name->function_name([argument 1, [argument 2, [argument 3, [argument 4]]]])