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.
You need a chr$ macro:
invoke ShellExecute,0, chr$("open"), chr$("msinfo32"), ...
Or use addr txOpen, addr txInfo ...
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
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.
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
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.
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
Thanks for your reply dedndave,
Are you able to provide a bit of code as an example?
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
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.