DWORD FormatMessage(
DWORD dwFlags, // source and processing options
LPCVOID lpSource, // message source
DWORD dwMessageId, // message identifier
DWORD dwLanguageId, // language identifier
LPTSTR lpBuffer, // message buffer
DWORD nSize, // maximum size of message buffer
va_list *Arguments // array of message inserts
);
LPTSTR lpBuffer, // message buffer , 缓冲区地址
long dwFormatFlags
long NULL
string MessageBuffer
long dwLastError
long nLen
string pText
long lpAddr
constant Long FORMAT_MESSAGE_ALLOCATE_BUFFER = 256
constant Long FORMAT_MESSAGE_IGNORE_INSERTS = 512
constant Long FORMAT_MESSAGE_FROM_SYSTEM = 4096
setnull(NULL)
dwFormatFlags =bitor( FORMAT_MESSAGE_ALLOCATE_BUFFER,FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_FROM_SYSTEM) ;
lpAddr= Addr(MessageBuffer)
nLen = FormatMessage(dwFormatFlags, NULL,dwLastError,1024, lpAddr,0,NULL)
if nLen <= 0 then return ""
pText = space(nLen + 1 )
memcpy(pText,lpAddr,nlen)
LocalFree(lpAddr)
return pText