Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is MFC DLL reentrant?

Is MFC DLL reentrant?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rp_suman
    wrote on last edited by
    #1

    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!"

    M 1 Reply Last reply
    0
    • R rp_suman

      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!"

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      You have the source code. I don't recall seeing anything thread safe in the MFC code.

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      R 1 Reply Last reply
      0
      • M Mark Salsbery

        You have the source code. I don't recall seeing anything thread safe in the MFC code.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        R Offline
        R Offline
        rp_suman
        wrote on last edited by
        #3

        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!"

        M 1 Reply Last reply
        0
        • R rp_suman

          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!"

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups