JWasm : INVOKE requires prototype

Started by SteveAsm, November 09, 2011, 04:54:56 PM

Previous topic - Next topic

SteveAsm

Hey guys,
(fyi, I cross-posted on the jwasm sourceforge site)

I'm working on porting a project I developed using Masm and Masm32 over to JWasm.
I'm experiencing some difficulty with regard to the limited (or missing) INC and/or LIB files.

This line of code:
      invoke free, eax

generates this error:
QuoteTest.asm(184) : Error A2159: INVOKE requires prototype for procedure

I have these Includes and IncludeLib's in my code:

    include ..\Include\windows.inc
    include ..\Include\CommCtrl.inc
    include ..\Include\commdlg.inc
    include ..\Include\oleauto.inc
    include ..\Include\windowsx.inc

    includelib ..\Lib\user32.lib
    includelib ..\Lib\gdi32.lib
    includelib ..\Lib\kernel32.lib
    includelib ..\Lib\comctl32.lib
    includelib ..\Lib\comdlg32.lib
    includelib ..\Lib\shell32.lib
    includelib ..\Lib\oleaut32.lib
    includelib ..\Lib\crtdll.lib
    includelib ..\Lib\msvcrt.lib


When programming in C, I would use these required headers: stdlib.h, malloc.h
However, they (or similar) are not a part of JWasm.

There are other instances as well where similar issues have cropped up regarding prototypes.
Any suggestions ?

RotateRight

Perhaps

free PROTO C :VARARG

in

msvcrt.inc

Surprised that other allocation functions were not flagged as welll though.

jj2007

#2
free is a macro and therefore will choke with invoke, in Masm as well as in Jwasm.
Correct syntax is free eax

Simple example:
include \masm32\include\masm32rt.inc

.code
start:
push alloc(1000)
MsgBox 0, hex$(eax), "alloc & free:", MB_OK
pop eax
free eax
exit
end start

jcfuller

I have stdio.inc and stdlib.inc which appear to have been converted with h2incx.

James

MichaelW

The choice of EAX to store the pointer to the allocated memory may also be an error. Since EAX, ECX, and EDX are not (normally) preserved across procedure calls, any procedure call between the allocation and the free could destroy the pointer.
eschew obfuscation

SteveAsm

Quote from: jcfuller on November 09, 2011, 06:47:55 PM
I have stdio.inc and stdlib.inc which appear to have been converted with h2incx.

I tried those.
Odd thing...,  when I use either of those, it generates a ton of errors.

Quote from: jj2007 on November 09, 2011, 06:13:27 PM
free is a macro and therefore will choke with invoke, in Masm as well as in Jwasm.
Correct syntax is free eax

Funny... because the masm version seems to work as intended.


QuotePerhaps
free PROTO C :VARARG
in
msvcrt.inc
Surprised that other allocation functions were not flagged as welll though.

msvcrt.INC is one of the files missing in jwasm.
I suppose I can reproduce it.
I was just wondering if those PROTOs were already reproduced somewhere.

jj2007

Quote from: SteveAsm on November 09, 2011, 07:35:16 PM
Quote from: jj2007 on November 09, 2011, 06:13:27 PM
free is a macro and therefore will choke with invoke, in Masm as well as in Jwasm.
Correct syntax is free eax

Funny... because the masm version seems to work as intended.

If you assemble the above snippet with JWasm, it works fine, too. There are only minor differences between JWasm.exe and ml.exe, and most people will never note any difference. My MasmBasic library - 12,000 lines, of which almost 6,000 lines of macros - assembles just fine with JWasm. However, you must use the Masm32 package. If you use the includes provided at the JWasm site, the behaviour will differ.

jcfuller

Steve,
  This works fine. Make sure you are using the includes from wininc. Note I use the msvcrt.lib in the batch file.

James



                        ;
;+---------------------------+
;|  use CRT (MSVCRT) in ASM  |
;+---------------------------+

    .386
    .MODEL FLAT, stdcall
    option casemap:none
     public _start

ifndef __POASM__
    .nolist
    .nocref
endif
WIN32_LEAN_AND_MEAN equ 1
    include \jwasm\wininc\include\windows.inc
    include \jwasm\wininc\include\stdio.inc
    include \jwasm\wininc\include\stdlib.inc
ifndef __POASM__
    .cref
    .list
endif

;--- CStr(): macro function to simplify defining a string

CStr macro pszText:VARARG
local szText
    .const
szText    db pszText,0
    .code
    exitm <offset szText>
endm

.data?
Argc dd ?
Argv db ?
CmdL LPSTR ?
    .CODE

_start:



Mymain  proc

    invoke printf, CStr("Hello, world!",10)
    invoke GetCommandLine
    mov CmdL,eax
    invoke strlen,eax
    mov Argc,eax
    invoke printf,CStr("%s",10),CmdL
    invoke printf, CStr("Lets try a malloc / free",10)
    invoke malloc,(1024)
    invoke free,eax

    ret

Mymain endp
  invoke Mymain
  invoke ExitProcess, NULL

    end _start



batch file I use to compile console mode


@setlocal
@ECHO OFF
@SET LIB=\jwasm\wininc\lib
@SET PATH=C:\jwasm;C:\jwasm\jwlink;c:\jwasm\wininc\lib;c:\jwasm\wininc;%PATH%
@REM add more libraries below
@SET LIBS=LIBRARY kernel32.lib, msvcrt.lib, user32.lib


jwasm  %1.asm
jwlink  system pe_con name %1.exe file %1.obj %LIBS% %2 %3 %4
REM ECHO All Done
endlocal




jcfuller

jj,
For his project he  can't use the masm32 package without violating the license so it must be jwasm all the way.

James

SteveAsm

Odd..., I submitted a post, but, it must have gotten clobbered, as it's not here.
Anyway,

I did discover something, that seems to have helped.
It appears that the order in which the includes are listed matters.


    include \jwasm\wininc\include\windows.inc
    include \jwasm\wininc\include\stdio.inc
    include \jwasm\wininc\include\stdlib.inc


If windows.inc is not at the top, as shown above, then errors are generated.
I had added stdio and stdlib to the top of the list, thus, errors were produced.
It all seems to be working now.

Thanks guys.

jj2007

Quote from: jcfuller on November 09, 2011, 08:14:13 PM
For his project he  can't use the masm32 package without violating the license so it must be jwasm all the way.

OK, misunderstanding. Thanks for clarifying, James.