Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LoadLibrary failing

207 views
Skip to first unread message

Jacob Ignatius

unread,
Jul 9, 2001, 12:38:36 PM7/9/01
to
I am trying to load a dll with the LoadLibrary function:

gsdll.hmodule = LoadLibrary(szDllName);
if (gsdll.hmodule < (HINSTANCE)HINSTANCE_ERROR)
return FALSE;
..
..
This code is in another dll but I can't see why that should be a problem.
Loadlibrary returns an error code - 1114 (A dynamic link library (DLL)
initialization routine failed).

When I use the same code in another application (exe) there is no problem.
What is the problem?


CheckAbdoul

unread,
Jul 9, 2001, 3:01:12 PM7/9/01
to

Run dependency walker on the DLL's to get the list of dependent dll's
and make sure that they are available in the path.

Also note that LoadLibrary(..) return value test has changed in 32-bit
world.

You should check for NULL { if ( gsdll.hmodule == NULL ) } instead of

if (gsdll.hmodule < (HINSTANCE)HINSTANCE_ERROR)

[ See LoadLibrary documentation ]

and use GetLastError(..) to get the error information.

Cheers
Check Abdoul
------------------


"Jacob Ignatius" <jac...@ais.co.uk> wrote in message
news:eWLOIZJCBHA.988@tkmsftngp07...

Sam Hobbs

unread,
Jul 9, 2001, 3:47:38 PM7/9/01
to
Do you have the source for the DLL being loaded?


"Jacob Ignatius" <jac...@ais.co.uk> wrote in message
news:eWLOIZJCBHA.988@tkmsftngp07...

Jacob Ignatius

unread,
Jul 10, 2001, 5:49:10 AM7/10/01
to
All the dlls gsdll depends on were loaded, so its nothing to do with
dependency.

I checked for NULL too and I keep getting NULL.

I don't know what to do.


CheckAbdoul <check...@yahoo.com> wrote in message
news:#rYDSkKCBHA.2116@tkmsftngp02...

Joseph M. Newcomer

unread,
Jul 12, 2001, 7:07:18 PM7/12/01
to
Your code is incorrect. It should be
module = LoadLibrary(name);
if(module == NULL)
return FALSE;

the (HINSTANCE)HINSTANCE_ERROR) is old Win16-style code and is
obsolete. Read the documentation of LoadLibrary.
joe

On Mon, 9 Jul 2001 17:38:36 +0100, "Jacob Ignatius" <jac...@ais.co.uk>
wrote:

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

Joseph M. Newcomer

unread,
Jul 12, 2001, 7:09:51 PM7/12/01
to
I forgot to add: use ::GetLastError to see why it failed.

HMODULE module = LoadLibrary(name);
if(module == NULL)
{
DWORD err = ::GetLastError();
.... report error here
return FALSE;
}

How you report the error is up to you. Alternatively, just return
FALSE and the caller can call ::GetLastError and report the error. If
you set a breakpoint on the return FALSE, set a watch on
@ERR,hr
and it will display the error code and message in the watch window.
joe

On Mon, 9 Jul 2001 17:38:36 +0100, "Jacob Ignatius" <jac...@ais.co.uk>
wrote:

>I am trying to load a dll with the LoadLibrary function:

Joseph M. Newcomer [MVP]

0 new messages