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

FormatMessage vs SetErrorMode(0)

11 views
Skip to first unread message

sds

unread,
Oct 7, 2009, 1:22:22 PM10/7/09
to
When I do this in my baz.exe :

SetErrorMode(0);
LoadLibrary("foo.dll");

I get a window with the error message:
"The procedure entry point bar could not be located in the dynamic
link library baz.exe"
(the reason is that foo.dll calls bar() which is defined in baz.exe
without __declspec(dllexport)).
and LoadLibrary returns NULL

However, if I use FormatMessage to get the error message instead:

FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), 0, (char*)&buf, 0, NULL);

I get this:

"The specified procedure could not be found."

Note that the crucial bits of information (function name bar and dll
name baz) are missing.
Is there a way to get the same error message which is displayed in the
error window using FormatMessage?
Thanks.
Sam.

Remy Lebeau

unread,
Oct 7, 2009, 2:06:15 PM10/7/09
to

"sds" <sam.st...@gmail.com> wrote in message
news:a3628710-a22f-4190...@f10g2000vbf.googlegroups.com...

> Is there a way to get the same error message which is displayed
> in the error window using FormatMessage?

No, there is not. The error message you are looking for is generated by the
OS Executable Loader itself when resolving its statically-linked inports.
It is not generated by LoadLibrary() or anything else in the Win32 API, and
thus is not accessible in your code.

--
Remy Lebeau (TeamB)


0 new messages