The following is a comprehensive example of a user-written DLL consisting of three subroutines and two functions. Note the use of the return value for the subroutines.
/********************************************************************
* Copyright (C) 1982-2016 ESL Syndetic Limited *
* All Rights Reserved. *
* *
* NOTICE *
* PROPRIETARY AND CONFIDENTIAL *
* *
*This computer program is and contains trade secret and confidential*
* and proprietary information of ESL Syndetic Limited. All use, *
* disclosure, and/or reproduction not specifically authorized in *
* writing by ESL Syndetic Limited is prohibited. This program may *
* also be protected under the copyright and trade secrets laws of *
* countries other than the U.S.A. *
* *
* ESL is a registered trademark of ESL Syndetic Ltd. *
********************************************************************/
#include <windows.h>
#include <esllib.h> // to use ESL string routines
// constants for subroutine errorlevel return values
#define ERROR_FREE 0
#define ERROR_OUT_OF_MEMORY 1
/*****************************************************
* HasUpper - Looks for an uppercase character in the *
* HSTRING. *
* *
* Returns TRUE if an uppercase character is found, *
* otherwise false. *
*****************************************************/
LONG ESLSUBAPI HasUpper(HSTRING esl_str)
{
int i, var;
char *str;
// Get the address of the string
str=EslQueryStringAddr(esl_str);
var=strlen(str);
// Look thru the string, character by character,
// for uppercase.
for (i=0;i<var;i++)
{
if(isupper((int)*str++))
return(TRUE);
}
return(FALSE);
}
/*****************************************************
* MakeUpper - Converts the HSTRING pointed at by *
* pEsl_str to uppercase characters. *
* *
* Returns ERROR_FREE if successful. *
*****************************************************/
LONG ESLSUBAPI MakeUpper(HSTRING *pEsl_str)
{
unsigned int i, size, copied;
char *str,*tmp_str;
// Get the address of the string
str=EslQueryStringAddr(*pEsl_str);
// Allocate enough space to hold a copy of
// the string.
size=strlen(str);
str=(char *)malloc(++size);
if( !str )
return ((LONG)ERROR_OUT_OF_MEMORY);
// Get a copy of the ESL string characters
copied=EslQueryStringChars(*pEsl_str,str,size);
// Convert the characters to uppercase
for(i=0,tmp_str=str;i<size;i++,tmp_str++)
{
*tmp_str=(char)toupper((int)*tmp_str);
}
// Copy the uppercase characters back to
// the HSTRING
EslSetStringValue(pEsl_str,str,--size);
// free memory
free(str);
return((LONG)ERROR_FREE);
}
/*****************************************************
* HasLower - Looks for a lowercase character in the *
* HSTRING. *
* *
* Returns TRUE if a lowercase character is found, *
* otherwise false. *
*****************************************************/
BOOL ESLFNCAPI HasLower(HSTRING esl_str)
{
int i, var;
char *str;
// Get the address of the string
str=EslQueryStringAddr(esl_str);
// Look thru the string, character by character,
// for lowercase.
var=strlen(str);
for (i=0;i<var;i++)
{
if(islower((int)*str++))
return(TRUE);
}
return(FALSE);
}
/*****************************************************
* MakeLower - Converts the HSTRING pointed at by *
* pEsl_str to lowercase characters. *
* *
* Returns ERROR_FREE if successful. *
*****************************************************/
LONG ESLSUBAPI MakeLower(HSTRING *pEsl_str)
{
unsigned int i,size,copied;
char *str,*tmp_str;
// Get the address of the string
str=EslQueryStringAddr(*pEsl_str);
// Allocate enough space to hold a copy of
// the string.
size=strlen(str);
str=(char *)malloc(++size);
if( !str )
return ((LONG)ERROR_OUT_OF_MEMORY);
// Get a copy of the Easel string characters
copied=EslQueryStringChars(*pEsl_str,str,size);
// Convert the characters to lowercase
for(i=0,tmp_str=str;i<size;i++,tmp_str++)
{
*tmp_str=(char)tolower((int)*tmp_str);
}
// Copy the lowercase characters back to
// the HSTRING
EslSetStringValue(pEsl_str,str,--size);
// free memory
free(str);
return((LONG)ERROR_FREE);
}
/*****************************************************
* MakeBackwards - Reverse the order of the letters in*
* the HSTRING pointed at by pEsl_str. *
* *
* Returns ERROR_FREE if successful. *
*****************************************************/
LONG ESLSUBAPI MakeBackwards(HSTRING *pEsl_str)
{
unsigned int i, size, copied;
char *str, *buff, tmp;
// Get the address of the string
str=EslQueryStringAddr(*pEsl_str);
// Allocate enough space to hold a copy of
// the string.
size=strlen(str);
buff=(char *)malloc(++size);
if( !buff )
return ((LONG)ERROR_OUT_OF_MEMORY);
// Get a copy of the Easel string characters
copied=EslQueryStringChars(*pEsl_str,buff,size);
// Reverse the order of the characters
for (i=0;i<copied/2;i++)
{
tmp=*(buff+copied-1-i);
*(buff+copied-1-i)=*(buff+i);
*(buff+i)=tmp;
}
// Copy the reversed characters back to
// the HSTRING.
EslSetStringValue(pEsl_str,buff,copied);
// free memory
free(buff);
return((LONG)ERROR_FREE);
}
/*****************************************************
* DLLMain - System Entry Point called by system. *
* Use Entry Point to Allocate, Initialize and Free *
* data structures plus other housekeeping processes. *
* *
* Returns TRUE *
*****************************************************/
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}