RE: LoadLibrary sometimes fails with error 14.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dan Elliott [MSFT] (dane_at_online.microsoft.com)
Date: 03/12/04


Date: Fri, 12 Mar 2004 21:14:04 GMT

This is a known issue in .NET CF v1.0. We believe that it is due to the
fact that CF does not unload P/Invoke'd dlls once they are loaded, but have
not been able to prove this conclusively. This would account for the dll
loading when the app is first launched, but failing to load later.

If this error occurs, it might be possible to unload unneeded modules by
P/Invoking to GetModuleHandle and FreeLibrary, then try the P/Invoke again.

try
{
    MyPInvoke();
}
catch (Exception x)
}
    string moduleName = "ModuleToUnload.dll";
    IntPtr hModule = GetModuleHandle(moduleName);
    if (IntPtr.Zero != hModule)
    {
        FreeLibrary(hModule);
    }
}

HTH,
Dan

This posting is provided "AS IS" with no warranties, and confers no rights.



Relevant Pages

  • Re: How are proxy-stub dlls freed?
    ... DLLs are not different from any other COM in-proc servers. ... When running an app from the PB IDE, it runs in the same process as the ... not unload them when it is unloaded, and since the process is still ...
    (microsoft.public.vc.atl)
  • Re: overlaying - how to deal with a big application?
    ... > If I could write dlls with VB6 I could do the jobs into dlls and load and ... > unload them manually, but this doesn't work with VB. ... > if the ressources would be freed also - is it true, ... has to take care about the use of system resources no matter how many ...
    (microsoft.public.vb.winapi)
  • Re: REXX problem
    ... Paul Ratcliffe wrote: ... let one use one of them in a loop and the other unload it - try to find a situation where the other can use the function after SysDropFuncs has run by the other. ... It probably does use the normal referencing technique to actually load and unload the DLLs, but registering the procedure names in the language is the all or nothing approach. ...
    (comp.os.os2.apps)
  • Re: Process not always exiting
    ... kernel32.dll can cause a hang on unload. ... but it hasn't unloaded DLLs yet). ... Threads waiting on sockets? ... > Any kind of pointers would be useful; If needed, I can provide a list of ...
    (microsoft.public.win32.programmer.kernel)
  • RE: Unload button not working on WinXP
    ... does all of iis hang? ... the issue causing the lock in the dll? ... Unload button not working on WinXP ... Our ASP calls into DLLs which then get locked by IIS, ...
    (microsoft.public.inetserver.iis)