Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

FormatMessage strange message

j_jimenez
Beginner
922 Views
If I try to load dynamicly a dll, and the file is corrupt, the error message I get (using GetLastError and FormatMessage functions) is:
"%1 is not a valid Win32 application"

What can I do with "%1"? In this case I know it is the name of the file. But in a different error it can change.

The dwLanguageId I am using is 1024 (Default language), so the error appears on the OS language.

Thanks
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
922 Views
Not many system error codes have arguments (%1, %2) etc. You can conveniently interpret them using FORMAT_MESSAGE_ARGUMENT_ARRAY, but you'll have to decide what to put there on case-by case basis.

Here's a sample which uses FORMAT_MESSAGE_FROM_STRING, but you can easily adapt it to FORMAT_MESSAGE_FROM_SYSTEM:
lpObjs = LOC('whateverdll.dll'C)
iLen = FormatMessage(FORMAT_MESSAGE_FROM_STRING+FORMAT_MESSAGE_ARGUMENT_ARRAY, &
       LOC(szFormat), idMsg, 0, LOC(szText), LEN(szText), LOC(lpObjs))
Note that Arguments argument requires double indirection -- it is an address of (an array of) address(es) of string(s).

Jugoslav
0 Kudos
j_jimenez
Beginner
922 Views
Thanks.
The problem now is, What to put on lpObjs? How do I know that the first argument is the dll name? What is the second argument?
0 Kudos
Jugoslav_Dujic
Valued Contributor II
922 Views
The complete list of error messages is in help page "System errors - numerical order" (there's link to it from GetLastError). There's only about a dozen messages containing arguments (like %1), and it's pretty obvious what kind of value is expected. (Of these, some ten refer to image names, and other few to drive names).

Jugoslav
0 Kudos
Reply