AutoHotkey Community

It is currently May 27th, 2012, 1:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: April 2nd, 2008, 9:23 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I did never needed it, but wrote this just in case somebody else needs this. This is nothing really spectacular and all arguments given to string can be retrieved via the built in variables %0%, %1% and up ... The string retrieved by this function is the full string used by Windows itself (including the options like "/restart").

edit: For example, this could be used for debugging.

Code:
; getCmdLine - get full command line string
; Public Domain 2008 Tuncay
; http://www.autohotkey.com/

/*
Function: getCmdLine
   Get the full command line string of current script, including the
   arguments to AutoHotkey.
   
Parameters:
   There are no parameters.
   
Return:
   Returns the full command line string.
   
ErrorLevel:
   ErrorLevel is changed by DllCall().
*/
getCmdLine()
{
   Return p2str(DllCall("GetCommandLine", "Str")) ; LPTSTR GetCommandLine(VOID)
}

/*
Function: p2str
   Get a pointers variable content as a string.
   
Parameters:
   _p - An address to a variable with a string content. (string pointer)
   
Return:
   Returns the "extracted" string.
*/
p2str(_p)
{
   ; Get the content of first character, to avoid in the Loop the need
   ; of "A_Index - 1" at each iteration.
   c := *(_p + 0)
   str .= Chr(c)
   Loop
   {
      If (c := *(_p + A_Index))
         str .= Chr(c)
      Else
         Break
   }
   Return str
}


edit: Corrected the DllCall argument from "int" to "str".


Last edited by Tuncay on March 29th, 2010, 10:08 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2008, 5:09 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Code:
MsgBox % DllCall("GetCommandLine","uint",0,"str")
:roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2008, 5:47 am 
Lexikos wrote:
Code:
MsgBox % DllCall("GetCommandLine","uint",0,"str")
:roll:


My old win32 help file wrote: LPTSTR GetCommandLine(VOID)

so:
msgbox, % DllCall( "GetCommandLine", "str" )
:wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2008, 10:24 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Haha, I must've been half asleep. Still am... Thankfully AutoHotkey corrects the stack pointer after DllCall, so it doesn't matter either way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2008, 8:37 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I am not that familiar with DllCall, thx for the correction. I see in the documentation, its documented.


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: Bon, sks and 17 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