Daniel Berger
2006-Dec-17 15:59 UTC
[Win32utils-devel] FormatMessage issue in eventlog.rb - more clues
Hi all,
Ok, I''m getting closer on this get_description failure and the
mscoree.dll file. It has something to do with the way we''re calling
FormatMessage(). Consider the following C code, which behaves exactly
the same way as the current Ruby code:
#include <windows.h>
#include <stdio.h>
int main(){
HMODULE hmod;
int rv;
char buf[4096];
char* dll = "C:\\WINDOWS\\system32\\mscoree.dll";
char* va_list[3];
int flags = FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ARGUMENT_ARRAY;
hmod = LoadLibraryEx(dll, 0, LOAD_LIBRARY_AS_DATAFILE);
printf("HMOD: %i\n", hmod);
va_list[0] = "store application started";
rv = FormatMessage(
flags,
hmod,
0,
0,
(LPTSTR)buf,
sizeof(buf),
va_list
);
printf("RV: %i\n", rv);
printf("BUF: %s\n", buf);
FreeLibrary(hmod);
return 0;
}
This will print "The operation completed successfully". Which, btw,
is
what GetLastError(39) returns. How that ends up getting assigned to the
buffer, I''m not sure.
Now, consider this approach:
int main(){
HMODULE hmod;
int rv;
char* message;
char* dll = "C:\\WINDOWS\\system32\\mscoree.dll";
int flags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_IGNORE_INSERTS;
hmod = LoadLibraryEx(dll, 0, LOAD_LIBRARY_AS_DATAFILE);
printf("HMOD: %i\n", hmod);
rv = FormatMessage(
flags,
hmod,
0,
0,
(LPSTR)&message,
0,
NULL
);
printf("RV: %i\n", rv);
FreeLibrary(hmod);
return 0;
}
This fails as expected.
More clues, but I''m still not sure what the appropriate solution is
yet.
Regards,
Dan
