I thank you all for you help, it was not easy to find the right solution to my problem, but I belive Ihave found the right solution which I would like to share with everybody. Also after reading this MS. article on dllmain reconmendation, and according to the article the C runtime library may not be properly initialized is certain cases so using th C memory allocation functions was out of the question.
MS article 'Best Practices for Creating DLLs'
http://msdn.microsoft.com/en-us/library/windows/hardware/gg487379.aspx[
^]
My solution:
file 'langdesc.h'
#ifndef LANGDESC_DEFINED
#define LANGDESC_DEFINED
#define TEXT_DEFAULT_ERROR "Unknown error number suplied"
#define TEXT_NO_ERROR "Info: no errors have been happend"
#define TEXT_INDEX_OUT_OF_BOUNDS "Index out of bounds error"
#define TEXT_LIST_EMPTY = "the list is empty, try adding an item to the list first!"
#endif LANGDESC_DEFINED
file 'errordesc.h'
#ifndef ERRORDESC_DEFINED
#define ERRORDESC_DEFINED
#ifdef __cplusplus
extern "C" {
#endif
#ifndef NULL
#define NULL ((void *)0)
#endif /* NULL */
#define ERROR_N0_ERROR 0
#define ERROR_DEFAULT_EROR 1
#define ERROR_INDEX_OUT_OF_BOUNDS 10
#define ERROR_LIST_EMPTY 11
extern int GetErrorDescription(const int number, char *pOut, const int out_size);
#ifdef __cplusplus
}
#endif
#endif /* ERRORDESC_DEFINED */
I came to the conclusion based on certain win32 functions like the RegQueryValueEx where it is posible to query the length of a string simply be setting the lpvalue parameter to NULL, the functions still returns success, but places the actually required size in the lpcbValue parameter, which is handy.
Also I do not use any of the C standards include libraries, so I created made the necessary functions by hand, I may be paranoid, but that's another discussion.
file 'errordesc.c'
#include "errordesc.h"
#include "langdesc.h"
int copy_text(char *dest, const char *source, const int dest_size);
int text_len(const char *source);
int GetErrorDescription(const int number, char *pOut, const int out_size)
{
const char *cp;
int iLen = 0;
switch (number)
{
case ERROR_N0_ERROR:
cp = TEXT_NO_ERROR;
break;
case ERROR_INDEX_OUT_OF_BOUNDS:
cp = TEXT_INDEX_OUT_OF_BOUNDS;
break;
case ERROR_LIST_EMPTY:
cp = TEXT_LIST_EMPTY;
break;
default:
cp = TEXT_DEFAULT_ERROR;
break;
}
if (pOut == NULL)
{
return text_len(cp);
}
iLen = copy_text(pOut, cp, out_size);
return iLen;
}
int copy_text(char *dest, const char *source, const int dest_size)
{
int i;
i = 0;
if (dest != NULL && source != NULL)
{
for (i = 0; i < (dest_size-1); i++)
{
if (source[i] == '\0')
{
dest[i] = '\0';
return i;
}
dest[i] = source[i];
}
}
dest[dest_size-1] = '\0';
return i;
}
int text_len(const char *source)
{
int iLen;
iLen = 0;
if (source != NULL)
{
while (source[iLen] != '\0')
{
iLen++;
}
}
return iLen;
}
How it works?.
-----------------
1. The problem I bump in to was how to define the error codes and the text itself, so I came with the following decalration:
TEXT_<descriptive error="" text=""> these are the actally text definitions
ERROR_<descriptive text=""> the are the error number definitions
#define TEXT_INDEX_OUT_OF_BOUNDS "Index out of bounds error"
#define ERROR_INDEX_OUT_OF_BOUNDS 10
By prefixing all the strings with either TEXT or ERROR it is very easy to in a switch statement.
3. adding a new error text is done in 4 steps:
-----------------------------------------------
step 1:
Add a line below the last define statement in the langspec.h file,
#define TEXT_SOME_ERROR "some error occured"
step 2.
Add another line below the last #define statement in the errordesc.h file,
#define ERROR_SOME_ERROR 20
Step 3.
Add three line below the last case statement in the errordesc.h file
case ERROR_SOME_ERROR:
cp = TEXT_SOME_ERROR;
break;
step 4.
Add ERROR_SOME_ERROR statement in a return statement or added it to a variable to hold the last error, a bit like how the GetLastErrror works.
3. This way these 3 files can be placed in a dll file to make a language file, also the use of the langdesc.h header file also make it fairly easy to change the error text between warious languages, also This little language file can easly be adjusted ti unicode with a couple of macros.