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

DisableThreadLibraryCalls() fails with "The specified module could not be found"

461 views
Skip to first unread message

Boris Schaeling

unread,
Jul 21, 2009, 3:06:23 PM7/21/09
to
I'm calling DisableThreadLibraryCalls() in DllMain() to suppress the
DLL_THREAD_ATTACH and DLL_THREAD_DETACH signals. However
DisableThreadLibraryCalls() always fails and returns 0. When I call
GetLastError() it says that the specified module could not be found (error
code 126).

I've used GetModuleFileName() to verify that the first parameter of
DllMain() is alright: GetModuleFileName() returns the correct filename.
Anyone with an idea why DisableThreadLibraryCalls() could fail? I'm using
VC++ 2008 SP1 on Vista Business SP2.

Boris

Paul Baker [MVP, Windows Desktop Experience]

unread,
Jul 21, 2009, 3:37:16 PM7/21/09
to
It is common courtesy to research your problem by reading the documentation
and using a search engine to look for similar posts.

The documentation gives two possible reasons for failure, at most one of
which you eliminated:
"The DisableThreadLibraryCalls function fails if the DLL specified by
hModule has active static thread local storage, or if hModule is an invalid
module handle"

There is a newsgroup post that seems to suggest that ERROR_MOD_NOT_FOUND is
indicative of a failure due to TLS.

Disable Thread Library Calls:
http://msdn.microsoft.com/en-us/library/ms682579(VS.85).aspx

BOOST Library:
http://groups.google.com/group/comp.programming.threads/browse_thread/thread/e2071a348b238d93/9ca269fd54a472a

Paul

"Boris Schaeling" <bo...@highscore.de> wrote in message
news:op.uxfl0xcmhcamje@bose...

Pavel A.

unread,
Jul 21, 2009, 3:38:34 PM7/21/09
to

From the docum:


"The DisableThreadLibraryCalls function fails if the DLL specified by
hModule has active static thread local storage"

--pa

Boris Schaeling

unread,
Jul 21, 2009, 4:30:51 PM7/21/09
to
On Tue, 21 Jul 2009 21:37:16 +0200, Paul Baker [MVP, Windows Desktop
Experience] <paulrich...@community.nospam> wrote:

> It is common courtesy to research your problem by reading the
> documentation
> and using a search engine to look for similar posts.
>
> The documentation gives two possible reasons for failure, at most one of
> which you eliminated:
> "The DisableThreadLibraryCalls function fails if the DLL specified by
> hModule has active static thread local storage, or if hModule is an
> invalid
> module handle"

Who would expect that the error message "The specified module could not be
found" means that thread-local storage is used? Eliminating reasons for
failure is creative but wouldn't increase my trust in code. Answers like
yours in Usenet do help though. So thanks to you and Pavel!

Boris

Paul Baker [MVP, Windows Desktop Experience]

unread,
Jul 22, 2009, 10:33:41 AM7/22/09
to
Yes, this error code does not lead you to the cause by itself. But I don't
see what else the function can do. I cannot thing of a more appropriate
Win32 error code. That is why you have to do the things I suggested ;)

I am not sure what trust has to do with it? The function did what it was
documented to do. If you expect a function always to do what *you* want it
to do, you will often be disappointed. And if you write code without reading
the documentation, you will get unexpected behaviour.

Now there are at least *two* posts about this syndicated all over the
Internet, so the next person will find it even easier to get the answer on
their own :)

Paul

"Boris Schaeling" <bo...@highscore.de> wrote in message

news:op.uxfpxpyjhcamje@bose...

0 new messages