how to unload the dll - page 4

 
OneDepo >> :

Yes, you're right, this will reduce the waiting time for dll rewrite, but it won't solve the main problem: unloaded indicator - change the dll! Clearly, the library is loaded via LoadLibrary(), the load counter is set to 1, but FreeLibrary() is apparently not called in deinit(). The counter is not reset to 0 and the dll is locked until the terminal is closed. I think so, but we need to check with the developers.

Who prevents (except for some participants of this branch) you from doing

#import "kernel32.dll".

int GetModuleHandleA ( string sss);
void FreeLibrary(int hhh);
#import


deinit()

{

handlissimo=GetModuleHandleA("test-dll.dll");

FreeLibrary(handlissimo) ;

}


???

You can fill in function parameters by yourself. To delete TOTALLY FROM MEMORY all DLL released this way - due to limitations of metatrader.exe and due to earlier mentioned by me strong caching in vindex (which includes substitution of protected dll files from dllcache) - use regsvr32.

I see that TheExpert is related to MetaQuotes.

 

Note: sometimes even regsvr32 does not unload the DLL, and Windows fills in an old version. Practice shows that a single DLL can be lying in memory for WEEKS. In this case only rebooting will help. If you do not want to restart, semi-hacker ways will help, such as Process Explorer. It can unload from memory anything from anywhere - contrary to what the vocationalists on this forum claim (and load too, ha ha, but you don't need it).

http://www.softpedia.com/get/System/System-Info/Process-Explorer.shtml

short description and plugin:

http://rootkits.su/app/ShowApp.aspx?id_a=36

 

I see you're still going at it. All right. Here's what MS itself tells us about regsvr32:


Regsvr32 tool: usage and error messages


"The Regsvr32 tool (Regsvr32.exe) is designed to register and unregister OLE controls, such as automatically registered DLL or OCX files. This may be necessary when troubleshooting some problems in Windows system, Microsoft Internet Explorer and other programs. For example, according to the Microsoft Knowledge Base article below, the Regsvr32.exe tool should be used to unregister Wuv3is.dll control before it is reinstalled from the Windows Update Center website.


more:

"The regsvr32.exe utility is used to register DLLs and ActiveX controls in the Windows registry. It can also be used to remove inconsistencies between DLL files."

 
HideYourRichess >> :

I see you're still going at it. All right. Here's what MS itself tells us about regsvr32:


Regsvr32 tool: Usage and error messages


"Regsvr32 (Regsvr32.exe) is used to register and unregister OLE controls like auto-registered DLL or OCX files. This may be necessary when troubleshooting some problems in Windows system, Microsoft Internet Explorer and other programs. For example, according to the Microsoft knowledgebase article below the Regsvr32.exe tool should be used to unregister the Wuv3is.dll control before reinstalling it from the Windows Update Center website."


more:

"The regsvr32.exe utility is used to register DLLs and ActiveX controls in the Windows registry. It may also be used for removing inconsistencies between DLL files."

Well, uncle hacker, you should have already guessed from your own last sentence how regsvr32 works for us:


http://support.microsoft.com/kb/207132

RegSvr32.exe calls the following Win32 functions in this order:

* OleInitialize
* LoadLibrary to load the DLL
* DllRegisterServer or DllUnregisterServer
* FreeLibrary
* OleUninitialize

http://msdn.microsoft.com/en-us/library/ms683152(VS.85).aspx
FreeLibrary Function

Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count.
When the reference count reaches zero, the module is unloaded from the address space of the calling
process and the handle is no longer valid.

That is, regsvr32 loads and releases the library. But unlike terminal.exe, which on its own or with a simple and elegant solution I suggested above, frees the library, BUT CONTINUES TO STAY IN MEMORY, (giving Windows reasons not to unload the library for now and let any other process do it) - unlike metatrader hanging in memory, the command line utility regsvr32.exe command line utility STOPS its PROCESS and EXIT from MEMORY, which instructs Windows to completely unload the library from memory.

A library can be unloaded without using regsvr32, but it's roulette. Some people like roulette, most pros don't, it's a matter of development level.

If the library is simple and does not cling to LOTS of other libraries, it MAY unload quickly. But if the library is complex, with database links and exotic controls, it can take minutes or even hours to be unloaded.

By the way, concerning AlwaysUnloadDLL parameter - Microsoft itself claims that this only worked until 2000 (further complicated algorithms are applied now to calculate "the need for a DLL"):

http://msdn.microsoft.com/en-us/library/bb776795(VS.85).aspx

Unloading the DLL

The Shell automatically unloads a DLL when its usage count is zero, but only after the DLL has not been used for a period of time. This inactive period might be unacceptably long at times, especially when a Shell extension DLL is being debugged. For operating systems prior to Windows 2000, you can shorten the inactive period by adding the following information to the registry.

  • HKEY_LOCAL_MACHINE
  • Software
  • Microsoft
  • Windows
  • CurrentVersion
  • Explorer
  • AlwaysUnloadDll
 

Since I'm still suffering from a bad cold (but mind you, even while lying in bed with a fever I help people solve their terminal.exe problems for free, i.e. solve their money problems exclusively), I can tell those interested (and also uninformed vocational school students) how difficult it is to work as sysadmins in large long-distance companies.

Any large company uses UNIVERSAL tools. This means that all servers - local and global runs Eorakl, on all workstations use the same program of the same version of the linkage Office, Excel-or analytical program with Eorakl or MS SQL Server, some "dbconnect.dll". And then one "wonderful" day for sysadmins developers finally debug a new version of the program and all local sysadmins (in the company of the first hundred - sysadmins can be 500-800, 1.250 Terabyte hard disc memory, 130 NCR nodes, 145 Unix server systems and 2600 Windows servers, 80,000 mail users in more than 2,000 corporate locations) comes an order to REPLACE "tomorrow" this program. The program is complex, it uses a lot of things, just rewriting it on the computer will not work. And it is necessary to reboot the computer after regsvr32 - if the sysadmin has time for it.

In this replacement can only be done from 18-00 to 24-00, because up to 18-00 office workers are still working on computers, and at 24-00 on the server starts service work on Yorakla, the stations are starting auto-updating Windows and auto-updating antivirus. There are means to REMOTE start regsvr32 and overload station without going to the station, but they do not always work, (Firewall enabled, not-logof-lenny user, etc.). And computers local sysadmin may be 50-100, far from each other, and on different floors, and in already closed offices.

So the sysadmins run around the company building and run regsvr32 by hand.

 

Regsvr32 is designed to register and unregister COM servers.

These are not all dlls. This is a special kind of dll. There is no need to call Regsvr32.

It is sufficient to call FreeLibrary as shown above or not to use "#import" but use the pair:

LoadLibrary, FreeLibrary.

By the way, my dlls are for some reason released immediately after removing the indicator.

 

Actually, personally, I am writing for those who can read Russian and English. Strange people, they repeat for the tenth time here WHY regsvr32 was created. They chant it like a mantra, like a spell, while others don't know why. And what does it matter if regsvr32 does what we need it to do and has no side effects?

It's like an ambulance or intensive care doctor prescribing sodium hyposulfite to an alcoholic ("advanced" one like that)

http://drugslist.ru/drugs/antichlor-sodium-thiosulfate/

and he starts shouting that he won't drink it because ..... is a photo fixer and they want to poison him!

http://www.rwwc.ru/recipe/index6.php

If there are so many clever people here, then let them point out OTHER standard utility, which is at hand on any computer, which would load and immediately unload ANY LIBRARY you want, so as to reset the caching of DLLs by Windows in this way.

 
AlexEro >> :

...

For the tenth time they repeat here WHY regsvr32 was created. What does it matter if regsvr32 does what we need it to do and has no side effects? They chant it like a mantra, like a spell.

It's like an ambulance or emergency room doctor prescribing sodium hyposulfite to an alcoholic ("advanced" one like that)

...

This is all very important. If you are making medical analogies, what you are writing here is like treating a sick head with an axe.


AlexEro >> :

...

Library unloading can happen WITHOUT using regsvr32, but it's roulette. Some people like roulette, most pros don't, it's a matter of level of development.

If the library is simple and does not cling to LOTS of other libraries, it MAY unload quickly. But if the library is complex, database-enabled, with exotic controls, it can take minutes or even hours to be unloaded.

...


You just don't understand how loading/unloading dll mechanism works in principle, that's why you have such sick fantasies on this subject. You should not use regsvr32, it is not intended for it.Also you should not try to unload library into deinit with FreeLibrary, the library should be unloaded by itself, if it has no gross errors of course. Your "simple and elegant solution" is nonsense. It will not work in many cases, especially if deadlocks occur within the DllMain.


I repeat, the only normal and correct way to unload a dll is to write the dll itself without errors. If dll is not unloaded normally - then coder's hands are crooked (namely the coder, in the terminal itself everything is done correctly) - that's all. I always, repeat, always unload dll normally, immediately after removal of indicator. And this is correct, it is the way it has been designed in the terminal.


And you are in vain trying to give weight to your fiction by referring to your experience as a sysadmin. We have already found out that you are not a very smart sysadmin, so it looks very childish, ridiculous.

 
HideYourRichess >> :
You just don't understand how the dll loading/unloading mechanism works in principle, that's why you have such sick fantasies on this topic.... (You also shouldn't try to unload a library to deinit using FreeLibrary, the library should be unloaded by itself, if there are no gross errors in it of course. Your "simple and elegant solution" is nonsense. It will not work in many cases, especially if deadlocks occur within the DllMain.
Uncle hacker, there is no logic in your words: if the library is ALWAYS unloaded, why "my" FreeLibrary call according to you "won't work in many cases"? What harm could come from an extra FreeLibrary call in the deinit() block? Would calling FreeLibrary() in your opinion somehow block the release of the library or something? That's not clear, uncle kool hacker, and it's obvious.
 
AlexEro >> :
Uncle hacker, there is no logic in what you are saying

1st question - how does the system know from which processes to unload the dll?

Question 2 - how do I find the entry point without loading the dll?


Now, essentially. The dll is loaded and unloaded during regsvr for correct registration. And of course this has no effect on unloading it from other processes.

Do not try to sound stupider than you are. You can read mana, though.

If the library HAS ALWAYS unloaded, why "my" FreeLibrary call according to you "won't work in many cases"? What harm could come from an extra FreeLibrary call in a deinit() block? Maybe your FreeLibrary() call will somehow block the release of the library, or what? Uncle kool hacker, and a clear one at that.

It's obvious. In addition to unloading the dll, the implementation of deinitialization of indicator (expert) can be anything directly related to it, which turns the unauthorized release of the dll into a hack, which in turn does not guarantee the correct operation of the terminal.


>> So, good luck, keep trying.

2All: don't think about hiring him as an admin.