Tech Support > Microsoft Windows > Development Resources > LoadLibrary fails with message "Module Not Found"
LoadLibrary fails with message "Module Not Found"
Posted by santosh on November 28th, 2003


Hi All ,
I am facing a problem with LoadLibrary wherein , when i try to load my
custom dll XYZ.dll from system32 it works fine. If i place the same
dll in Program Files/Custom Folder/XYZ.dll and try to load it ,
LoadLibrary fails with error number 0x7E meaning Moudule Not Found.

I try to find out the dependencies , with Depends.exe and my custom
dll XYZ.dll depends on dlls only from System32 meaning it doesn't
depend on any other custom dlls.

What might be the problem???
Any help is greatly appreciated...

-Santosh
//KRLoadLibraryFails

Posted by Mark S on November 28th, 2003


I believe LoadLibrary looks for the DLL in the current directory of the
running application, and then along the directories specified in the PATH
environment variable.

The system32 folder probably is in your path. ...\Program Files\Custom
Folder probably is not.

"santosh" <krcdacin@yahoo.co.in> wrote in message
news:ac6b14c8.0311272237.295beeff@posting.google.c om...


Posted by Frank Hickman on November 28th, 2003


Depends.exe will only show you the libraries that get loaded during a normal
startup. If the functionality provided by your XYZ.dll is not part of the
normal startup then it would not show up. For example: If you did a
LoadLibrary in OnInitInstance it should show up, if however your LoadLibrary
was in some function that only gets called by say a user selecting a
particular menu option then it would not show up. Actually, now that I
think about it, I believe depends.exe will only show dlls from which you
have directly linked to import libraries for, anyone, correct me here if I
am wrong. In any event, when you changed the location of your dll did you
change the path in the LoadLibrary API? Or did you add the path that you
installed the dll in to the environment variable PATH?

--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.


"santosh" <krcdacin@yahoo.co.in> wrote in message
news:ac6b14c8.0311272237.295beeff@posting.google.c om...


Posted by santosh on November 28th, 2003


Hi ,
I am calling LoadLibrary from an EXE. This exe and dll are stored in
the same folder. I am getting the folder path in the registry. Before
LoadLibrary i am rading the registry entry and appending the XYZ.dll
to the read value before passing it to LoadLibrary...

Basically i have written a control panel applet (.cpl). on the double
click of the apllet i am doing LoadLibrary to my XYZ.dll.

-Santosh.

Posted by Belgarath on November 28th, 2003


On 28 Nov 2003 03:00:47 -0800, krcdacin@yahoo.co.in (santosh) wrote:

If it's in the same folder, you don't need to give a full path. Just
the filename will do. (your default working directory anyway...)

Belgarath

Posted by santosh on November 28th, 2003


Hi ,
LoadLibrary succedes on on my machine, ie win 2k Version 5.0 (Build
2195; Service Pack 4).

and gives eroor message Module Not Found on the other win 2k machine

-Santosh

Posted by Alex Blekhman on November 29th, 2003


"Belgarath" <support@microsoft.com> wrote in message
news:sgbesv4r0r0d931tc6ua27uopn0cvlfapc@4ax.com...
Hm.. I was always thinking that Control Panel applets run under
%WINDIR%\system32 folder. Whether it's true or false, there is very simple
solution. From your EXE get its full path - GetModuleFileName(NULL, ...),
then cut from it EXE file name and append DLL file name. Then call
LoadLibrary with full path of DLL. It should always work.



Posted by Boris Dynin on November 30th, 2003


Just to be safe you could do the following:

1. Call Win32 function 'GetModuleFileName' passing 'hModule' of your exe as
parameter.
2. Returned string will contain full pathname of your exe.
3. Strip filename from the pathname and use what's left to build pathname of
the DLL.
4. Use the full pathname of DLL in 'LoadLibrary()' call.

Hope it helps,
Boris

"santosh" <krcdacin@yahoo.co.in> wrote in message
news:ac6b14c8.0311280300.478a492a@posting.google.c om...


Posted by John Brown on November 30th, 2003


Some of these questions might be basic, but:

1) Did you remember to add the path to your DLL to the Registry on the
other machine?

2) As another poster said, you don't need to specify the full path if
the DLL is in the same folder as the EXE. Have you tried
LoadLibrary("MyDLL.dll")?

3) You said that your program depends only on DLLs in system32. Are
these DLLs also present in system32 on the other machine?

4) Did you just copy your EXE and DLL to the other machine, or did you
build a setup program?

5) Is the other machine running the same versions of Win2K and
Internet Explorer?

If the answer to (3) was no, then (4) and (5) may be relevant.