Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:36:55+00:00 2026-05-30T19:36:55+00:00

I am trying just to print out the value of argc using the CommandLineToArgvW

  • 0

I am trying just to print out the value of argc using the CommandLineToArgvW Window’s API function in NASM. The following is what I have:

extern _ExitProcess@4
extern _GetCommandLineA@0
extern _CommandLineToArgvW@8
extern printf

global _start
section .code

Format:
    db "%d",10,0
FormatS:
    db "%s",10,0
_start:
    push ebp
    mov ebp, esp
    sub esp, 4 ; Create empty space for ArgC
    call _GetCommandLineA@0
    push eax; Push value beneath ArgC
    mov ebx, ebp ; Set ebx to ebp
    sub ebx, 4
    push dword ebx ; pushes ArgC address onto stack
    push dword [ebp - 8] ; pushes pointer to Command Line String
    call _CommandLineToArgvW@8
    push dword [ebp - 4]
    push Format
    call printf
    push dword 0
    call _ExitProcess@4

No matter what I do, the value for argc is 1. What am I doing wrong?

I assemble and link with these commands:

nasm -fwin32 FunctionTests.asm
golink FunctionTests.obj kernel32.dll msvcrt.dll shell32.dll /console /entry _start
FunctionTests.exe hi asdf asdf asdf asdf

As you can see, from the last line, argc should be 6.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:36:56+00:00Added an answer on May 30, 2026 at 7:36 pm

    Change _GetCommandLineA to _GetCommandLine*W* CommandLineToArgv expects a pointer to a UNICODE string.

    MASM but just about the same:

    start:
        push    ebp
        mov     ebp, esp
        sub     esp, 4
    
        call    GetCommandLineW
    
        lea     ecx, dword ptr[ebp - 4] ; need the address of local
        push    ecx                     ; address of local
        push    eax                     ; pointer to unicode string
        call    CommandLineToArgvW
    
        push    dword ptr [ebp - 4]     ; value of local
        push    offset Format
        call    crt_printf
        add     esp, 8
    
        ; this is all?  Then we don't have to restore stack.
        push    0
        call    ExitProcess
    end start
    

    and this is the output:

    D:\Projects>ConTest.exe boo boo I see you

    6

    D:\Projects>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to print a value using switch-case base off
I'm trying to put a 'print out' function call in a Haskell function. (a
I'm trying to print out a float number, that has the value 5 What
I am trying to connect QWebpage::windowCloseRequested() to a slot that just prints out a
I am trying to print formatted xml to a file but my XmlNodePrinter just
I've been playing around trying to thoroughly understand Reference and Value types. Just when
I am trying to print out the name of the month not the integer
I have a program that uses XSL-FO (org.apache.fop.apps.Driver) to generate a PDF print out
I'm just starting out with SML, and I'm trying to modify some code so
I'm learning Objective-C and just trying out some sample code. I am getting the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.