AutoHotkey Community

It is currently May 26th, 2012, 10:35 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: September 9th, 2009, 2:45 pm 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2009, 7:50 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
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 :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2009, 2:36 pm 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
Thanks very much.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2009, 6:42 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2009, 7:51 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
:!: Thanks SKAN

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: JSLover, Miguel, rbrtryn and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group