How static objects are distributed between DLLs and Windows binary memory

I have a problem with the design of the DLL, I am currently, as you can call it, and since wikipedia refers to it the Hell DLL The problem is this:

I created a system with several modules implemented as DLLs. They are used in the application, and the DLL can be loaded, but not all of them are necessary. If only things such as math are done, they can refer to "Utilities.dll" and use this. The problem is that I have logger / tracer. This writes everything to a file and the debug console for me, the debug console is just a stream. The problem is how to work with multiple DLLs trying to work with the same class of logs. Seeing how the log class is located in this "Utilities.dll", and things like "DataManagers.dll" and other dlls also want to use the log class function. This includes writing to a file. I am currently using critical sections to make sure that no write conflicts occur,but browsing critical sections is done in usermode. At some point, I will have to switch to mutexes or similarly have kernel mode objects. But this having multiple instances of the log class in the DLL's memory means that I am having serious problems if I just use a critical section.

What I cannot minimize is the way that all DLLs can use the same instance of the log class, without having to reference Utilities.dll one at a time. I don’t want to load 8 dlls into my demo project, and all 8 of them belong to the same DLL as the journal class, this will be a bit of a chain reaction if I need more things like the journal class. Is there a way to do this right? Use the functionality of a class with static functions inside a DLL in another DLL and in a binary .exe format, using the same "static" functions, thereby not encountering write to the log file or even the output stream for the debug console.

, - , . , similair Singleton DLL,

:

  • DLL , , .

, ( , ). , '09. " " , , DLL?

+3
3

"DLL Hell".

DLL. DLL . , DLL DLL, . DLL (, ), .

. , , . , Utilities.DLL .

, . . , . , , .

+5

WinApi CreatePipe CreateNamedPipe, Windows:

    BOOL WINAPI CreatePipe(
  __out         PHANDLE hReadPipe,
  __out         PHANDLE hWritePipe,
  __in          LPSECURITY_ATTRIBUTES lpPipeAttributes,
  __in          DWORD nSize
);

    HANDLE WINAPI CreateNamedPipe(
  __in          LPCTSTR lpName,
  __in          DWORD dwOpenMode,
  __in          DWORD dwPipeMode,
  __in          DWORD nMaxInstances,
  __in          DWORD nOutBufferSize,
  __in          DWORD nInBufferSize,
  __in          DWORD nDefaultTimeOut,
  __in          LPSECURITY_ATTRIBUTES lpSecurityAttributes
);

ReadFile WriteFile /.

ReadFile. ReadFile , : , .

WriteFile , , . , , WriteFile , ReadFile, .

/ .

: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365780(v=vs.85).aspx

0

As seen from the picture below image,

It’s actually very common (against a very popular opinion) that one DLL is displayed several times in the process! This is a basic understanding of how a DLL works :-)

In a clean Windows XP system, you can see several instances of dxtmsft.dll, ieframe.dll, iepeers.dll, etc. in the iexplore.exe process. All these Dlls are simply displayed at different addresses.

0
source

All Articles