Hi!
I have a problem freeing a memory which was allocated in a .DLL file. I found this in a "dbgheap.c" file -> "Pointers from
non-local heaps cannot be handled. For example, a non-local pointer may come from a DLL that has the CRT linked-in."
So, my question is, how can I free a memory which was allocated in a .DLL file?
This is the code:
in .DLL file I have two files compiled, translate.c and translate.h
Code:
/*
TRANSLATE.C
*/
# include <windows.h>
# include <time.h>
# define DLL_EXPORT
# include "translate.h"
char *ReadLanguage (LPCTSTR SectionName, LPCTSTR KeyName, LPCTSTR lpDefault, DWORD nSize, LPCTSTR FileName)
{
char *ReadedString = NULL;
if ((ReadedString = malloc (sizeof (char) * nSize)) != NULL)
{
GetPrivateProfileString (SectionName, KeyName, lpDefault, ReadedString, nSize, FileName);
}
else
{
// error checking
printf ("Error occured!");
}
return ReadedString;
}
Code:
/*
TRANSLATE.H
*/
# ifndef TRANSLATE_H
# define TRANSLATE_H
# ifndef DLL_EXPORT
# define DLL_SPEC __declspec (dllimport)
# else
# define DLL_SPEC __declspec (dllexport)
# endif
// function prototype
char DLL_SPEC *ReadLanguage (LPCTSTR SectionName, LPCTSTR KeyName, LPCTSTR lpDefault, DWORD nSize, LPCTSTR FileName);
# endif // TRANSLATE_H
Now, everything is compiled into a "cui.dll" file.
And this is the project that is using the .DLL file.
Code:
/*
MAIN.C
*/
# include <windows.h>
# include <stdio.h>
# include <time.h>
# include "translate.h"
# pragma comment (lib, "cui.lib")
int main ()
{
char *TempINI = NULL;
if ((TempINI = ReadLanguage ("BLA", "KEY_1", "NULL", 80, "./en.lng")) == NULL) // ReadLanguage is in a .DLL file
{
printf ("Error occured!");
}
else
{
if ((short) atoi (TempINI))
{
printf ("VICTORY!");
}
free (TempINI); TempINI = NULL; // this is where the unhandled exception raises
}
return 0;
}
So, if anyone knows how could this problem be solved, PLEASE tell me.
Thank you!