News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using a C++ lib in mASM, having trouble with .DEF

Started by David, November 27, 2009, 07:04:54 PM

Previous topic - Next topic

David

Hi guys, I made a lib in C++ to help me out with file io's in mASM

C++ File

#include <iostream>

using namespace std;

void xwriteFile(char *filepath, char* line1, char* line2, char*line3, char*line4)
{
ofstream writer;
... //etc
}

bool xcheckExists(char *filepath)
{
// checks to see if file exists by opening it if it exists return true, else return false
}


C++ .DEF file

LIBRARY   xfileio
DESCRIPTION "FileIO for mASM"
EXPORTS
   xwriteFile   @1
   xcheckExists   @2




mASM inc file? Is this correct??

xwriteFile proc :DWORD :DWORD :DWORD :DWORD :DWORD
xcheckExists proc :DWORD


mASM .def file
absolutely no idea whatsoever

Okay so my questions are:

Is my inc file correct?
How do I do my mASM def file?
How do i know if xcheckExists returns true? will eax be 1 if true, and 0 if false?  so all I would do is invoke xcheckExists, addr filepath then
.if eax == 1
; it returned true>
else
;it returned false?
.endif

dedndave

QuotexwriteFile proc :DWORD :DWORD :DWORD :DWORD :DWORD
should be:
xwriteFile proto :DWORD :DWORD :DWORD :DWORD :DWORD
"proto" is short for prototype
take a look inside the windows.inc file, as well as the others for examples
\masm32\include\*.*

drizz

Quote from: David on November 27, 2009, 07:04:54 PM
Hi guys, I made a lib in C++ to help me out with file io's in mASM

C++ File

#include <iostream>

using namespace std;

void xwriteFile(char *filepath, char* line1, char* line2, char*line3, char*line4)
{
ofstream writer;
... //etc
}

bool xcheckExists(char *filepath)
{
// checks to see if file exists by opening it if it exists return true, else return false
}

you need <extern "C"> before functions so they don't get mangled by the c++ compiler.
but only for static library

Quote from: David on November 27, 2009, 07:04:54 PM

C++ .DEF file

LIBRARY   xfileio
DESCRIPTION "FileIO for mASM"
EXPORTS
   xwriteFile   @1
   xcheckExists   @2



there is no need for DEF file if you are writing a static library, for dll see my next answer.

Quote from: David on November 27, 2009, 07:04:54 PM
How do I do my mASM def file?
mASM .def file
absolutely no idea whatsoever
not needed (and def is def, there is no masm special def syntax) .

you need 1) lib file 2) function/variable prototype/definition

Quote from: David on November 27, 2009, 07:04:54 PM
Is my inc file correct?

xwriteFile proto C :ptr sbyte, :ptr sbyte, :ptr sbyte, :ptr sbyte, :ptr sbyte
xcheckExists proto C :ptr sbyte
the default calling convention in c is CDECL if you didn't know, can be overriden with commandline.
the default calling convention in masm is specified in commandline or with ".model flat, <LANGUAGE>"

masm also has type checking if you didn't know.
"char" is "signed byte" if you don't put /j switch for cl

Quote from: David on November 27, 2009, 07:04:54 PM

How do i know if xcheckExists returns true? will eax be 1 if true, and 0 if false?  so all I would do is invoke xcheckExists, addr filepath then
.if eax == 1
; it returned true>
else
;it returned false?
.endif

cout << true << " is true" << endl;
cout << false << " is false" << endl;
what do you expect it to return? 666?

true equ 1
false equ 0

.if eax == true
.else
.endif

or just

.if eax
.else
.endif


i suggest you use jahphets include files/package, it has all the "std" lib headers translated which will make it easier for you to code in jwasm/masm and use all C functions like printf etc..
(http://www.japheth.de/)

alse search forum for linking and using c runtime with your masm program.

The truth cannot be learned ... it can only be recognized.

drizz

forgot to mention that using c++ classes in exported functions will definitely require you to link c runtime with your masm program.
and by that i mean to link it the right way by having main/WinMain and no overridden entrypoint.
The truth cannot be learned ... it can only be recognized.