Is MFC DLL reentrant?
-
Is the MFC DLL created with option "Regular DLL using shared MFC DLL" is reentrant / thread-safe? If not, how to create reentrant DLL using VC 2005? Thanks in advance!! Suman
-- "Programming is an art that fights back!"
You have the source code. I don't recall seeing anything thread safe in the MFC code.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
You have the source code. I don't recall seeing anything thread safe in the MFC code.
Mark Salsbery Microsoft MVP - Visual C++ :java:
Hi Mark, It seems, reentrancy is wholly depend on the code. Here are some rules for code to be reentrant: Reentrancy[^] And the code is as follows, the dll function will give the content of given file name:
void extern "C" __declspec(dllexport) getFileContent(LPCTSTR strFile, LPCTSTR& lpStrOut) { CFile pFile; pFile.Open(strFile, CFile::modeRead); int iLen = pFile.GetLength(); char *ch = new char[iLen+1]; pFile.Seek(0, CFile::begin); pFile.Read(&ch[0], iLen); ch[iLen] = '\0'; lpStrOut = ch; pFile.Close(); }
The function is reading file content into character array and returns pointer to the content. As it does not use any static variable, but allocating and returning "new" character array, is it reentrant? With Thanks & Regards, Suman-- "Programming is an art that fights back!"
-
Hi Mark, It seems, reentrancy is wholly depend on the code. Here are some rules for code to be reentrant: Reentrancy[^] And the code is as follows, the dll function will give the content of given file name:
void extern "C" __declspec(dllexport) getFileContent(LPCTSTR strFile, LPCTSTR& lpStrOut) { CFile pFile; pFile.Open(strFile, CFile::modeRead); int iLen = pFile.GetLength(); char *ch = new char[iLen+1]; pFile.Seek(0, CFile::begin); pFile.Read(&ch[0], iLen); ch[iLen] = '\0'; lpStrOut = ch; pFile.Close(); }
The function is reading file content into character array and returns pointer to the content. As it does not use any static variable, but allocating and returning "new" character array, is it reentrant? With Thanks & Regards, Suman-- "Programming is an art that fights back!"
As long as all the calls made in the function are reentrant then you're OK. Additionally, "new" is thread safe. On a side note, "ch" should be of type TCHAR*, not a char*, since you're using generic text mappings (the 'T' in LPCTSTR). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: