 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
hughman
Joined: 11 Feb 2007 Posts: 166
|
Posted: Wed Sep 09, 2009 1:45 pm Post subject: need help for dllcall winapi FormatMessage |
|
|
the definition of this function is
| Code: |
DWORD WINAPI FormatMessage(
__in DWORD dwFlags,
__in_opt LPCVOID lpSource,
__in DWORD dwMessageId,
__in DWORD dwLanguageId,
__out LPTSTR lpBuffer,
__in DWORD nSize,
__in_opt va_list *Arguments
);
|
My funtion
| Code: |
FormatMessageFromSystem(ErrorCode)
{
VarSetCapacity(Buffer, 500)
DllCall("FormatMessage"
, "UInt", 0x1000 ; FORMAT_MESSAGE_FROM_SYSTEM
, "Int", 0
, "Int", ErrorCode
, "Int", 0
, "UInt", &Buffer
, "UInt", 500
, "Str", NULL)
Return Buffer
}
|
but it always return null. How should I fix it? |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4652 Location: AHK Forum
|
Posted: Wed Sep 09, 2009 6:50 pm Post subject: |
|
|
Check out this, can be always useful WindowsDataTypes
This should work
| Code: | MsgBox % FormatMessageFromSystem(0x1100)
FormatMessageFromSystem(ErrorCode)
{
VarSetCapacity(Buffer, 2000)
DllCall("FormatMessage"
, "UInt", 0x1000 ; FORMAT_MESSAGE_FROM_SYSTEM
, "UInt", 0
, "UInt", ErrorCode
, "UInt", 0x800 ;LANG_SYSTEM_DEFAULT (LANG_USER_DEFAULT=0x400)
, "UInt", &Buffer
, "UInt", 500
, "UInt", 0)
VarSetCapacity(buffer,-1)
Return Buffer
} |
_________________ AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun  |
|
| Back to top |
|
 |
hughman
Joined: 11 Feb 2007 Posts: 166
|
Posted: Thu Sep 10, 2009 1:36 pm Post subject: |
|
|
| Thanks very much. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Fri Sep 11, 2009 5:42 am Post subject: |
|
|
VarSetCapacity(buffer,-1) can be avoided:
EITHER
| Code: | MsgBox % FormatMessageFromSystem(0x1100)
FormatMessageFromSystem(ErrorCode)
{
VarSetCapacity(Buffer, 2000)
DllCall("FormatMessage"
, "UInt", 0x1000 ; FORMAT_MESSAGE_FROM_SYSTEM
, "UInt", 0
, "UInt", ErrorCode
, "UInt", 0x800 ;LANG_SYSTEM_DEFAULT (LANG_USER_DEFAULT=0x400)
, "Str", Buffer
, "UInt", 500
, "UInt", 0)
Return Buffer
} |
OR
| Code: | MsgBox % FormatMessageFromSystem(0x1100)
FormatMessageFromSystem(ErrorCode)
{
VarSetCapacity(Buffer, 2000, 32 )
DllCall("FormatMessage"
, "UInt", 0x1000 ; FORMAT_MESSAGE_FROM_SYSTEM
, "UInt", 0
, "UInt", ErrorCode
, "UInt", 0x800 ;LANG_SYSTEM_DEFAULT (LANG_USER_DEFAULT=0x400)
, "UInt", &Buffer
, "UInt", 500
, "UInt", 0)
Return Buffer
} |
|
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4652 Location: AHK Forum
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|