LoadLibraryEx#include <windows.h> #include <stdio.h>#include <lmerr.h>void DisplayErrorText( DWORD dwLastError );#define RTN_OK 0 #define RTN_USAGE 1 #define RTN_ERROR 13int __cdecl main( int argc, char *argv[] ) { if(argc != 2) { fprintf(stderr,"Usage: %s <error number>\n", argv[0]); return RTN_USAGE; } DisplayErrorText( atoi(argv[1]) ); return RTN_OK; }void DisplayErrorText( DWORD dwLastError ) { HMODULE hModule = NULL; // default to system source LPSTR MessageBuffer; DWORD dwBufferLength; DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM ; // // If dwLastError is in the network range, // load the message source. // if(dwLastError >= NERR_BASE && dwLastError <= MAX_NERR) { hModule = LoadLibraryEx( TEXT("netmsg.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE ); if(hModule != NULL) dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE; } // // Call FormatMessage() to allow for message // text to be acquired from the system // or from the supplied module handle. // if(dwBufferLength = FormatMessageA( dwFormatFlags, hModule, // module to get message from (NULL == system) dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language (LPSTR) &MessageBuffer, 0, NULL )) { DWORD dwBytesWritten; // // Output message string on stderr. // WriteFile( GetStdHandle(STD_ERROR_HANDLE), MessageBuffer, dwBufferLength, &dwBytesWritten, NULL ); // // Free the buffer allocated by the system. // LocalFree(MessageBuffer); } // // If we loaded a message source, unload it. // if(hModule != NULL) FreeLibrary(hModule); } After you compile this program, you can insert the error code number as an argument and the program will display the text. For example:C:\> netmsg 2453 Could not find domain controller for this domain
呵呵,我也想这样咧。问其他高人吧,论坛中搜索一下。Google 搜。
我想起来了 他用的 API 写的,没用控件.自己用API封一个类...就这么个办法.要不用别人写好的.
xcopy mfc42.dll %windir%
xcopy msvcrt.dll %windir%
xcopy MSCOMM32.OCX %windir%
regsvr32 %windir%\MSCOMM32.OCX
1。 运行上面的命令 ,注册控件。
把上面的东西用文本文件保存,然后改后缀名为 .bat2。 还有就是在程序中注册控件调用 WinAPI 也可、。MSCOMM32.OCX 就这东东沙。
#include <stdio.h>#include <lmerr.h>void
DisplayErrorText(
DWORD dwLastError
);#define RTN_OK 0
#define RTN_USAGE 1
#define RTN_ERROR 13int
__cdecl
main(
int argc,
char *argv[]
)
{
if(argc != 2) {
fprintf(stderr,"Usage: %s <error number>\n", argv[0]);
return RTN_USAGE;
} DisplayErrorText( atoi(argv[1]) ); return RTN_OK;
}void
DisplayErrorText(
DWORD dwLastError
)
{
HMODULE hModule = NULL; // default to system source
LPSTR MessageBuffer;
DWORD dwBufferLength; DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM ; //
// If dwLastError is in the network range,
// load the message source.
// if(dwLastError >= NERR_BASE && dwLastError <= MAX_NERR) {
hModule = LoadLibraryEx(
TEXT("netmsg.dll"),
NULL,
LOAD_LIBRARY_AS_DATAFILE
); if(hModule != NULL)
dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
} //
// Call FormatMessage() to allow for message
// text to be acquired from the system
// or from the supplied module handle.
// if(dwBufferLength = FormatMessageA(
dwFormatFlags,
hModule, // module to get message from (NULL == system)
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
(LPSTR) &MessageBuffer,
0,
NULL
))
{
DWORD dwBytesWritten; //
// Output message string on stderr.
//
WriteFile(
GetStdHandle(STD_ERROR_HANDLE),
MessageBuffer,
dwBufferLength,
&dwBytesWritten,
NULL
); //
// Free the buffer allocated by the system.
//
LocalFree(MessageBuffer);
} //
// If we loaded a message source, unload it.
//
if(hModule != NULL)
FreeLibrary(hModule);
}
After you compile this program, you can insert the error code number as an argument and the program will display the text. For example:C:\> netmsg 2453
Could not find domain controller for this domain