Author Topic: GetCommandLine - winApi fn  (Read 5978 times)

0 Members and 1 Guest are viewing this topic.

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
GetCommandLine - winApi fn
« on: July 06, 2021, 04:55:25 am »
Yo Sprigssy and others...
can i do that in qb64:

Code: QB64: [Select]
  1. Declare Function GetCommandLine Lib "kernel32.dll" Alias "GetCommandLineA" () as String
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

FellippeHeitor

  • Guest
Re: GetCommandLine - winApi fn
« Reply #1 on: July 06, 2021, 05:00:02 am »
You don't declare an external function directly, it must be inside a DECLARE LIBRARY block.

However, for that example specifically, we already have COMMAND$

Code: QB64: [Select]

FellippeHeitor

  • Guest
Re: GetCommandLine - winApi fn
« Reply #2 on: July 06, 2021, 05:03:51 am »
See examples of declaring a library at http://www.qb64.org/wiki/Windows_Libraries

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: GetCommandLine - winApi fn
« Reply #3 on: July 06, 2021, 05:28:11 am »
Hi Felipe
I don't ask about using this "aka" version of api function with print than
i want invoke this function like this :

 string fname = GetCommandLine ()

then parse fname to extract just file name from full path .
is that possible with COMMAND$  ?

oK..i will look into wiki first...
« Last Edit: July 06, 2021, 05:29:30 am by Aurel »
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: GetCommandLine - winApi fn
« Reply #4 on: July 06, 2021, 05:40:50 am »
Ah i see i need  system dll declaration using DECLARE...
( dude..that blue wiki examples killing my eyes..heh )
ok

Code: QB64: [Select]
  1.  DECLARE DYNAMIC LIBRARY "Kernel32"
  2. Function  GetCommandLineA& ()
  3.  

hmm i see two ways ,ok i will try both...

another is presented by Dav !!!

Code: QB64: [Select]
  1. Function  GetCommandLine  Alias GetCommandLineA  ()
  2.  
« Last Edit: July 06, 2021, 05:47:02 am by Aurel »
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

FellippeHeitor

  • Guest
Re: GetCommandLine - winApi fn
« Reply #5 on: July 06, 2021, 06:08:50 am »
Code: QB64: [Select]
  1. FOR c = 1 TO count
  2.     a$ = COMMAND$(c)
  3.     'do whatever you need with this parameter
  4.  

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: GetCommandLine - winApi fn
« Reply #6 on: July 06, 2021, 06:11:08 am »
thanks Felipe
so that is how work..cool and simple
if that work then there is no need for api calls
« Last Edit: July 06, 2021, 06:12:57 am by Aurel »
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: GetCommandLine - winApi fn
« Reply #7 on: July 06, 2021, 06:24:41 am »
Yes
work as expected...
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

FellippeHeitor

  • Guest
Re: GetCommandLine - winApi fn
« Reply #8 on: July 06, 2021, 07:58:12 am »
Command$(0) actually returns your own program name. User parameters start at index 1.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: GetCommandLine - winApi fn
« Reply #9 on: July 06, 2021, 09:12:31 am »
Very similar to argv[0] in C/C++

Questions - 1) Is it only the program name if that name is available? In other words, if the host does not provide it, is it NULL?  2) And it "represents" the program name, not necessarily is the program name, is that also true (from the ISO C11 standard) or does QB64 use the compiled name, or the executable (If after I compile I decide to rename the binary)?

According to the C++ Standard, section 3.6.1 (See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf):
Quote
... argv[0] shall be the pointer to the initial character of a NTMBS that represents the name used to invoke the program or ""


Command$(0) actually returns your own program name. User parameters start at index 1.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: GetCommandLine - winApi fn
« Reply #10 on: July 06, 2021, 09:15:48 am »
@George McGinn Command$(0) will be the full path that is resolved to the running executable. Give it a try.
Shuwatch!

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: GetCommandLine - winApi fn
« Reply #11 on: July 06, 2021, 09:22:09 am »
Quote
Command$(0) actually returns your own program name.

Yes Felipe ..i want that
situation ..usage

text editor open file
with ShellExecute we call our program
which receive this file path and do execution/processing...etc
simple isn't ?
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: GetCommandLine - winApi fn
« Reply #12 on: July 06, 2021, 09:24:42 am »
Quote
Command$(0) will be the full path that is resolved to the running executable

exactly... ;)


PS..stupid me i figured why my editor don't run .exe ..heh because of
directory name with . (dot) in 1.5 so i changes into 1_5 and voila !!!
« Last Edit: July 06, 2021, 09:35:59 am by Aurel »
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: GetCommandLine - winApi fn
« Reply #13 on: July 06, 2021, 09:29:38 am »
It will get the name of the executable, even the new name after renaming it.

So, unlike the mainframe compilers that put the compiled name in the binary (was used to check to make sure the right name was used to invoke it, part of security checking back then), this command must do a DIR type of command to fetch where and what the executable is.

Note: The security checking was to make sure that a renamed binary was not inserted into a production system. Yes, there were ways around it, and when CICS came about, more robust module integrity checks were put into place (some by me back then). Something similar can be done in QB64,


Thanks.

@George McGinn Command$(0) will be the full path that is resolved to the running executable. Give it a try.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: GetCommandLine - winApi fn
« Reply #14 on: July 06, 2021, 09:31:52 am »
@George McGinn It's using argv and argc.... like any other C/C++ program would

Code: C++: [Select]
  1. func_command_count = argc;
  2. func_command_array = argv;
Shuwatch!