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. Preventing multiple instance creation in DLL

Preventing multiple instance creation in DLL

Scheduled Pinned Locked Moved C / C++ / MFC
7 Posts 4 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.
  • 0 Offline
    0 Offline
    0v3rloader
    wrote on last edited by
    #1

    Hello, I am working on a Dll that can't create more than one thread instance and thus would like to know what I can do to prevent that from happening. Thank you. Dave

    D 1 Reply Last reply
    0
    • 0 0v3rloader

      Hello, I am working on a Dll that can't create more than one thread instance and thus would like to know what I can do to prevent that from happening. Thank you. Dave

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      dNimrod#X wrote: ...a Dll that can't create more than one thread instance... Are you wanting only one instance of the DLL to exist, or are you wanting the DLL to only be able to create one thread, or is the DLL failing to create more than one thread and you want to know how to create additional threads?


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      A 0 2 Replies Last reply
      0
      • D David Crow

        dNimrod#X wrote: ...a Dll that can't create more than one thread instance... Are you wanting only one instance of the DLL to exist, or are you wanting the DLL to only be able to create one thread, or is the DLL failing to create more than one thread and you want to know how to create additional threads?


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        A Offline
        A Offline
        Alexander M
        wrote on last edited by
        #3

        I also don't understand what this guy wants from us. It is very unclear. Are you meaning that you just want one thread created by the dll for every process, or do you mean only one thread for the whole system? Don't try it, just do it! ;-)

        1 Reply Last reply
        0
        • D David Crow

          dNimrod#X wrote: ...a Dll that can't create more than one thread instance... Are you wanting only one instance of the DLL to exist, or are you wanting the DLL to only be able to create one thread, or is the DLL failing to create more than one thread and you want to know how to create additional threads?


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          0 Offline
          0 Offline
          0v3rloader
          wrote on last edited by
          #4

          I'm sorry if I wasn't clear enough... Allow me to explain what I need to do: I have to create a Dll, which is loaded at startup time and should be accessible by any application. Among many different features, this Dll creates a kind of console for output purposes only. So, all applications loading the Dll, can get direct access to this "output console" (and other features.) My problem is I can't let the Dll get duplicated each time an app loads it. This is why I am asking you for your help as I have never attempted to do this in a Dll. Actually I have never had this need before. What would you suggest me to do? Dave BTW: Perhaps I can prevent this from happening if all the applications use GetModuleHandle, instead of loading them?

          S A 2 Replies Last reply
          0
          • 0 0v3rloader

            I'm sorry if I wasn't clear enough... Allow me to explain what I need to do: I have to create a Dll, which is loaded at startup time and should be accessible by any application. Among many different features, this Dll creates a kind of console for output purposes only. So, all applications loading the Dll, can get direct access to this "output console" (and other features.) My problem is I can't let the Dll get duplicated each time an app loads it. This is why I am asking you for your help as I have never attempted to do this in a Dll. Actually I have never had this need before. What would you suggest me to do? Dave BTW: Perhaps I can prevent this from happening if all the applications use GetModuleHandle, instead of loading them?

            S Offline
            S Offline
            shiraztk
            wrote on last edited by
            #5

            Hi Am not sure if it will work or if its the correct way. Created a shared variable, so that this variable will be shared among the all the loaded Dll. #pragma data_seg(".DAT") int NumberofInstance 0 #pragma data_seg() .. .. NumberofInstance++; if(NumberofInstance>1) { Dont load the DLL. } in the Def file add this SECTIONS .DAT Read Write Shared Hope this will help you. Regards Mohamed Shiraz The Best Relligion is Science. Once you understand it, you will know God.

            0 1 Reply Last reply
            0
            • 0 0v3rloader

              I'm sorry if I wasn't clear enough... Allow me to explain what I need to do: I have to create a Dll, which is loaded at startup time and should be accessible by any application. Among many different features, this Dll creates a kind of console for output purposes only. So, all applications loading the Dll, can get direct access to this "output console" (and other features.) My problem is I can't let the Dll get duplicated each time an app loads it. This is why I am asking you for your help as I have never attempted to do this in a Dll. Actually I have never had this need before. What would you suggest me to do? Dave BTW: Perhaps I can prevent this from happening if all the applications use GetModuleHandle, instead of loading them?

              A Offline
              A Offline
              Alexander M
              wrote on last edited by
              #6

              check if this console window exists from DllMain and create it if now. Then create an API for writing text on that window. The API should get the window handle from the console window and send messages to it which are processed then in the process context that created the window. Don't try it, just do it! ;-)

              1 Reply Last reply
              0
              • S shiraztk

                Hi Am not sure if it will work or if its the correct way. Created a shared variable, so that this variable will be shared among the all the loaded Dll. #pragma data_seg(".DAT") int NumberofInstance 0 #pragma data_seg() .. .. NumberofInstance++; if(NumberofInstance>1) { Dont load the DLL. } in the Def file add this SECTIONS .DAT Read Write Shared Hope this will help you. Regards Mohamed Shiraz The Best Relligion is Science. Once you understand it, you will know God.

                0 Offline
                0 Offline
                0v3rloader
                wrote on last edited by
                #7

                Hi and thanks for the reply! That is exactly what I need to do. I would have accomplished it by now if it wasn't for one thing: this Dll of mine has MFC support and thus I don't have access to the DllMain procedure! I do have access to CWinApp::InitInstance. How can I prevent the Dll from loading twice? Perhaps I'm just confusing (and confused) with all this Dll business...

                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