News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

SEARCHING FOR EXAMPLES

Started by FJRusso53, December 12, 2023, 08:40:56 AM

Previous topic - Next topic

FJRusso53

The MASM32 help files are a little short on examples.  It has some but never the ones I need.
e.g invoke exist proc lpszFileName:DWORD

I have tried the following but getting no results;

pop hld ; address of a string holding the file name
; I have tried using just the file name 'file.xxx'
; and also with the name and location, 'c:\...\file.xxx'
;
invoke exist proc hld   <--- this fails to compile - missing operator  ???
invoke exist, addr hld  <--- compiles but never returns a hit

Where can I find some working examples?

Vortex

Hi FJRusso53,

Did you check the examples folder?

\masm32\examples

NoCforMe

#2
Your syntax is all screwed up.

The function is defined (in masm32\m32lib\exist.asm) as
exist proc lpszFileName:DWORD
so the way** to call it is
    INVOKE    exist, <pointer to filename>
where "filename" is a zero-terminated ASCII string.

On a second look, did you really code this?
pop hld ; address of a string holding the file name
If so, what you just did was to overwrite the contents of "hld" (presumably a variable with the address of the filename whose existence you want to check) with random garbage from the stack. If you take that statement out, it might work.

** The good, easy way, that is. You could use the "old school" push-push-call, but why? INVOKE is much cleaner and it checks for the right number of parameters for you, which is nice when you're calling a function that take 14 parameters ...
Assembly language programming should be fun. That's why I do it.

Vortex

Hi FJRusso53,

Here is a quick example for you :

include     \masm32\include\masm32rt.inc

.data

file        db 'Build.bat',0
msg1        db 'Build.bat does not exist.',0
msg2        db 'Build.bat exists.',0
table       dd OFFSET msg1,OFFSET msg2

.data?

.code

start:

    invoke  exist,ADDR file
   
    invoke  StdOut,DWORD PTR [table+4*eax]

    invoke  ExitProcess,0

END start