Re: Call Library Function & DLL Attach and Detach Calls



Tomi M wrote:I used the code below.#include <iostream>#include <fstream>BOOL APIENTRY DllMain( HANDLE hModule,                       
DWORD  ul_reason_for_call,                       
LPVOID lpReserved                     ){     using namespace std;    ofstream out("C:\log.txt", ios::app);    switch (ul_reason_for_call)    {    case DLL_PROCESS_ATTACH:        out << "DLL_PROCESS_ATTACH" << endl;         break;    case DLL_THREAD_ATTACH:        out << "DLL_THREAD_ATTACH" << endl;         break;    case DLL_THREAD_DETACH:        out << "DLL_THREAD_DETACH" << endl;         break;    case DLL_PROCESS_DETACH:        out << "DLL_PROCESS_DETACH" << endl;         break;    }    return TRUE;} TomiLabVIEW
simply uses LoadLibrary() to load a shared library into memory. It has
no direct control of how Windows will initialize that DLL inside the
LoadLibrary() function. It may be that the DLL is already loaded
somewhere, somehow or that Windows decides that it needs not to
initialize the DLL anymore. As to why and how this could happen you
would be better of asking MS or some low leverl Windows API guru, not
NI.

Have you tried to create a test app that loads your DLL with
LoadLibrary() and frees it afterwards with FreeLibrary() to see how it
works there? Unless you can proof that it is different there, there is
absolutely no use in trying to investigate an issue in LabVIEW of which
you don't even know if it is somehow LabVIEW related. The multiple
PROCESS_DETACH might be related to multiple FreeLibary() calls by
LabVIEW in different situations to make sure the DLL is always properly
purged. Windows has a somewhat strange refcount for DLL loads that can
lead especially in multi-threading applications to the situation that
eventhough you matched every LoadLibrary() call with a FreeLibrary()
call, the DLL still remains in memory until the parent process
completely terminates.

Rolf Kalbermatter
.



Relevant Pages

  • Re: .Net packaging/wrapper application?
    ... it just didn't work well in reality due to DLL ... Windows works is to look in the executable's directory for a needed DLL ... the way apps used to work when they developed Windows. ... Looks to me like Jim is looking for the .NET equivalent of compiling ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Unnown process... 5eplorer.exe
    ... do not remove the cause (a "super"-hidden .dll program) but only remove ... symptom files and registry settings. ... It has all permissions but 'copy' denied to everyone, ... then by using the Windows XP Recovery Console. ...
    (microsoft.public.win2000.general)
  • Re: WinSxS, functional under 2k ?
    ... The newSide-by-Side Assembly technology was introduced with Windows XP to help reduce or eliminate DLL Hell. ... If you recall earlier Windows versions, like Windows 95, when you installed an application you were warned if the installer tried to replace a DLL from the system folder with an older version and you were asked if you wanted to accept the change. ... Until Windows XP it wasn't so easy to use different versions of shared system DLLs, that is what the new Side-by-Side assemblies attempts to resolve. ...
    (microsoft.public.win2000.general)
  • Re: Determine name and path of dropped object?
    ... MDE I would really suggest the use of external DLL to hold the subclassing ... windows after loading the Microsoft Office Visual Basic Editor, ... Public Declare Sub DragAcceptFiles Lib "shell32.dll" _ ...
    (microsoft.public.access.modulesdaovba)
  • Re: .Net packaging/wrapper application?
    ... the simple answer to DLL Hell for Visual Basic apps was simply to place a copy of the needed DLLs in the same directory as your executable. ... The way Windows works is to look in the executable's directory for a needed DLL BEFORE using the registry to find one EVEN IF THE REFERENCED DLL IS REGISTERED ON THE PC RUNNING THE APPLICATION THAT NEED IT. ... Perhaps I'm getting old and but what really bothers me is nobody seems to notice this--maybe the 80s was before they got into programming. ... Looks to me like Jim is looking for the .NET equivalent of compiling with static libraries to produce a single executable. ...
    (microsoft.public.dotnet.framework.aspnet)