The MASM Forum

General => The Campus => Topic started by: Shintaro on April 29, 2014, 08:34:15 PM

Title: using ShellExecute to start msinfo32
Post by: Shintaro on April 29, 2014, 08:34:15 PM
Hi,

Using:
WinAsm 5.1.8.0
Created a Dialog project.

OS: Windows 8.1 64bit

Included Shell32.inc and Shell32.lib

I am trying to get ShellExecute to start msinfo32.

invoke ShellExecute,0,"open", "msinfo32",NULL,NULL,SW_SHOW

I would have thought that would have started msinfo32. But I get a compiler error on the above line:

C:\Temp\Assembly\Projects\test.asm(22) : error A2084: constant value too large
C:\Temp\Assembly\Projects\test.asm(22) : error A2114: INVOKE argument type mismatch : argument : 3

I'm not trying to do anything special, just trying to learn how to use the api correctly.

Any help would be greatly appreciated.
Title: Re: using ShellExecute to start msinfo32
Post by: jj2007 on April 29, 2014, 08:54:08 PM
You need a chr$ macro:

invoke ShellExecute,0, chr$("open"), chr$("msinfo32"), ...

Or use addr txOpen, addr txInfo ...
Title: Re: using ShellExecute to start msinfo32
Post by: Vortex on April 30, 2014, 04:47:28 AM
Hi aparsons,

Jochen is right. You need to use the chr$ macro. You can also try the code below :

include     \masm32\include\masm32rt.inc

.data

operation   db 'open',0
file        db 'msinfo32',0

.code

start:

    invoke ShellExecute,0,ADDR operation,ADDR file,NULL,NULL,SW_SHOW

    invoke ExitProcess,0

END start

Title: Re: using ShellExecute to start msinfo32
Post by: Shintaro on April 30, 2014, 09:51:28 AM
Thanks guys,

I appreciate your replies.

Just a couple of quick questions:
What types is the api call expecting, by default? Because I am trying to pass a string and maybe it is expecting an Int?

Is this defined anywhere? Because the MS API just say's, from my limited understanding, that how I used that API, it should have worked.

Cheers.
Title: Re: using ShellExecute to start msinfo32
Post by: dedndave on April 30, 2014, 11:57:52 AM
it wants the address of a null-terminated string, which is a dword

    .DATA

szString db 'String',0


to get the address, use the ADDR or OFFSET operator
in this case, i prefer OFFSET

    INVOKE  StdOut,offset szString
Title: Re: using ShellExecute to start msinfo32
Post by: Shintaro on April 30, 2014, 02:53:31 PM
Thanks dedndave,

I have spent too much time in other languages. It never occurred to me about a null terminated string.

Thanks again.

Vortex,

I had a look at masm32rt.inc, nice!
At this stage I just want stuff to work so masm32rt makes it easy for me.

Cheers.
Title: Re: using ShellExecute to start msinfo32
Post by: dedndave on April 30, 2014, 11:15:43 PM
now that you see how it works, you can use the chr$ macro
it defines the string in the .DATA section and exits with the offset   :biggrin:
the downside is that you can only get the offset one time
Title: Re: using ShellExecute to start msinfo32
Post by: Shintaro on May 03, 2014, 02:08:35 PM
Thanks for your reply dedndave,

Are you able to provide a bit of code as an example?
Title: Re: using ShellExecute to start msinfo32
Post by: dedndave on May 03, 2014, 02:26:36 PM
first, you can view the chr$() macro to see what it does
from \masm32\macros\macros.asm...
      chr$ MACRO any_text:VARARG
        LOCAL txtname
        .data
          IFDEF __UNICODE__
            WSTR txtname,any_text
            align 4
            .code
            EXITM <OFFSET txtname>
          ENDIF

          txtname db any_text,0
          align 4
          .code
          EXITM <OFFSET txtname>
      ENDM

it switches to the .DATA section, assigns the data, then returns with the offset
i think it was Jochen that mentioned it earlier in this thread
but, here is one way to use it
    INVOKE  MessageBox,0,chr$("Message"),chr$("Title"),MB_OK
here's another
    mov     edx,chr$("String")    ;EDX = address of "String",0
and another
    print   chr$("Hello World"),13,10
that one demonstrates that a "VARARG" can be a number of items
Title: Re: using ShellExecute to start msinfo32
Post by: zedd151 on November 06, 2015, 07:27:22 AM
I would simply use the 'fn' macro:


fn ShellExecute,0,"open", "msinfo32",NULL,NULL,SW_SHOW


;)

The fn macro takes care of alloting the data, and zero terminating the strings.