mabye someone know how to fix the problem,

i defined a class:



CRgb_CRgb PROTO :DWORD,:DWORD,:DWORD,:DWORD

CLASS CRgb
;public
virtual CRgb:r,g,b ;constructor
virtual SetRed:red
virtual SetGreen:green
virtual SetBlue:blue
virtual GetRGB

;private
long m_red
long m_green
long m_blue
ENDCLASS

...
..
<rest of methods here>
..
..
CRgb_CRgb proc me,r,g,b
m2m [ecx].CRgb.m_red, r
m2m [ecx].CRgb.m_green, g
m2m [ecx].CRgb.m_blue, b
ret
CRgb_CRgb endp

CRgb_$CRgb proc me
ret
CRgb_$CRgb endp


when i try to create an object like this in some other function/method of a class


LOCAL rgb:DWORD
mov ebx,ecx ; preserve 'me'
set rgb as CRgb
mov rgb,new(CRgb,255,0,0) ; code crashes here


if i clean the code with no parameters on the constructor it all runz fine.
any idea??
Posted on 2004-06-16 12:15:21 by wizzra
The constructor must not be "virtual", but "void" :)
and "CLASS" in uppercase ... means to me a modified ATC ... "warranty void"
The line "mov ebx,ecx ; preserve 'me'"
is also disturbing me, the only good excuse for this is if the procedure is a method of another class, that is marked as "C++ compatible"
Posted on 2004-06-16 12:37:43 by Ultrano
hi Ultrano,

thank you for your reply,
ATC is simply amazing (among NaN's work as well).

i didn't notice the 'void' part in the tutorials than ;) or i did and i mis-connecting it to the constructor.

naa, 'CLASS' is just a simple CLASS TEXTEQU <class> ;)

@The line "mov ebx,ecx ; preserve 'me'"
is also disturbing me@

yeah, i do it only if i using it in another method.
soemtimes APIs tend to destroy ecx (i think ECX is too generic to be an object pointer in my view) so i just save it as not so generic register among apis.

thanks for you help!!
keep up the great work
regards,
wizzra
Posted on 2004-06-16 12:44:46 by wizzra
btw,
i haven't noticed it yet, but does ATC supports function's signature?

i.e:

virtual myMethod: var1
virtual myMethod: var1,var2
virtual myMethod: var1,var2,var3

thanks ;)
Posted on 2004-06-16 12:56:12 by wizzra
nope, I decided not to implement this (though it's possible)
Posted on 2004-06-16 13:41:15 by Ultrano
here is a nice MACRO additions to the ATC ToolSet
i hate long typing :)

; //////////////////// mNEW Macro ////////////////////////


;
; Multi NEW Object Creation Macro
; By Wizzra, for the ATC Macro Tool Set
;
mNEW MACRO ClassName,Objects:VARARG
LOCAL tClass,b1,b2,line
tClass TEXTEQU <ClassName>
b1 TEXTEQU <(>
b2 TEXTEQU <)>

ifidn tClass,<>
exitm
else
FOR arg,<Objects>
line TEXTEQU <>
line CATSTR line,<mov arg,new b1 tClass b2>
%line
ENDM
endif
endm


usage: mNEW ClassName,<object arguments>

create by the compiler is the folowing:


mNEW CFont,obj,obj1,obj2 ; macro usage

; by compiler
mov obj, new(CFont)
mov obj1, new(CFont)
mov obj2, new(CFont)


; added 17.6.2004
; //////////////////// mVAR Macro ////////////////////////
another variant of the above macro is to produce for us automatically variables with thier datatype,
again, for lazy coders ;)



;
; Multi VAR Creation Macro
; By Wizzra, for the ATC Macro Tool Set
;
mVAR MACRO VarType,Objects:VARARG
LOCAL tVariable,line
tVariable TEXTEQU <VarType>

ifidn tVariable,<>
exitm
else
FOR arg,<Objects>
line TEXTEQU <>
line CATSTR line,<tVariable arg>
%line
ENDM
endif
endm


usage:


mVAR long,dwExStyle,lpClassName

compiler produces:
long dwExStyle
long lpClassName
Posted on 2004-06-16 19:30:56 by wizzra
I like it :)
Although ATC doesn't support signature, it does support checking #of params
virtual MyMethod1:var1
virtual MyMethod2:var1,var2
virtual MyMethod3:var1,var2,var3
Using incorrect #params with icall and pcall will cause compiletime error messages to be generated by atc, if you don't specify the params like this in class definitions and make calls with bad param counts, it'll still compile, but crash on you and leave you perplexed since your source will appear to be ok...
The StartStack and EndStack macros can help track down the source of such a problem, should you bravely choose to define your class methods without paramcount checking.
Posted on 2004-06-17 05:11:23 by Homer
Also for anyone else interested in ATC, you cannot have any parameters in your Constructor method..
If you need them, the solution is to create a secondary method and call it immediately after using the "new macro".
I often call it Create or Initialize, but if those names are already taken, just be creative - you need a new one :)

example:
mov pPlayer1, new (CPlayer)
set pPlayer1 as CPlayer
pcall pPlayer1.Create, CTEXT("PlayerMesh.x"), 3
Posted on 2004-06-17 05:34:07 by Homer
hi EvilHomer2k,

ultrano showed me the solution to have a constructor with Parameters,




;define extra DWORD for the 'me' pointer
myClass_myClass PROTO :DWORD,DWORD,DWORD

class myClass
void myClass:param1,param2 ; notice the 'void' macro
long a
long b
endclass

myClass_myClass proc me,param1,param2
m2m me.myClass.a,param1
m2m me.myClass.b,param2
ret
myClass_myClass endp
Posted on 2004-06-17 05:46:08 by wizzra
Yup, Homer skipped the tutorial with custom constructor :P
Over 30 versions ot ATC - I didn't supply a list of changes, so I'm the reason for this confusion :o .

myClass_myClass PROTO :DWORD,DWORD,DWORD
... ATC ver 32 supplies this automatically ;)
:( I haven't documented this, too. Sorry. Since I don't remember any other important changes, I assume this is the only undocumented thing. Have fun :)
Posted on 2004-06-17 07:46:46 by Ultrano
yup, just tested without the proto type constructors,
works great.
i though just frmo your tut that we should,
so less writing now ;)
thanks ultrano :)
Posted on 2004-06-17 07:55:08 by wizzra
and here I am STILL using secondary constructors as a fix to the custom constructor issue !!!
Jeez, I need to get with the times !!

Ultrano, post the latest someplace so I can merge it with mine :tongue:
I've made some small changes, including the addition of (macros driving procs) supporting Logging-to-textfile etc. which I've found to be a major benefit during debugging (especially of complex nested classes).
Posted on 2004-09-07 01:26:44 by Homer
here you go :)

sorry that I can't make the COM stuff any soon
Posted on 2004-09-08 02:58:53 by Ultrano
hi Ultrano,

i dunno why, but you class.inc does not compile.

my 'edited' version 32 works fine,
version 33 of yours doesn't.

here are the compile errors of 33:



C:\masm32\INCLUDE\class.inc(946) : error A2034: must be in segment block : malloc_func
C:\masm32\INCLUDE\class.inc(956) : error A2006: undefined symbol : How
C:\masm32\INCLUDE\class.inc(956) : error A2114: INVOKE argument type mismatch : argument : 3
C:\masm32\INCLUDE\class.inc(958) : fatal error A1010: unmatched block nesting : malloc_func


which reffers to this lines:


ifndef is_lib
ifndef malloc_func
malloc_func proc PUBLIC uses ebx ecx edx esi edi How
ifndef HEAP1
.data
HEAP1 dd 0
.code
endif
.if !HEAP1
invoke HeapCreate,0,10000,0
mov HEAP1,eax
.endif
invoke HeapAlloc,HEAP1,HEAP_ZERO_MEMORY,How
ret
malloc_func endp

..
..
..


now, if we will declair like this:


HeapFree proto :DWORD,:DWORD,:DWORD
HeapAlloc proto :DWORD,:DWORD,:DWORD
malloc_func proto :DWORD
free_func proto :DWORD
realloc_func proto :DWORD,:DWORD


it will compile fine, but we will get a linker error:

oopTest.obj : error LNK2001: unresolved external symbol _malloc_func@4
oopTest.obj : error LNK2001: unresolved external symbol _free_func@4
oopTest.exe : fatal error LNK1120: 2 unresolved externals


something is not declaired in the appropriate place...

i will upload my version 32 here (compileable), to fix the 32 version i had to remove the definitions to the end.
Posted on 2004-09-09 07:57:21 by wizzra
it's just that you're missing a ".code" line before "include class.inc". I use only my base.inc, so I'm saved all startup boring work :)
Posted on 2004-09-09 08:04:40 by Ultrano
yeah it works now if its in the .code area.
thanks :)

hey ultrano,

how about adding those to the next build of atc?



; //////////////////////////////////////////
; Additions to the ATC Macro Set, by Wizzra
; /////////////////////////////////////////
mINIT MACRO ClassType,Register,InitNumber,Objects:VARARG
LOCAL tClass,tReg,tNum,line
tClass TEXTEQU <ClassType>
tReg TEXTEQU <Register>
tNum TEXTEQU <InitNumber>
;mov [DestReg].classtype.member,0
ifidn tClass,<>
exitm
endif

ifidn tReg,<>
exitm
endif

ifidn tNum,<>
exitm
endif

FOR arg,<Objects>
line TEXTEQU <>
line CATSTR line,<mov [tReg]. tClass. arg,tNum>
%line
ENDM
ENDM

mCOPY MACRO ClassType,DestRegister,SourceRegister,Objects:VARARG
LOCAL tClass,dReg,sReg,tNum,line
tClass TEXTEQU <ClassType>
dReg TEXTEQU <DestRegister>
sReg TEXTEQU <SourceRegister>
;m2m [DestReg].classtype.member,[SourceReg].classtype.member
ifidn tClass,<>
exitm
endif

ifidn dReg,<>
exitm
endif

ifidn sReg,<>
exitm
endif

FOR arg,<Objects>
line TEXTEQU <>
line CATSTR line,<m2m [dReg]. tClass. arg, [sReg]. tClass. arg>
%line
ENDM
ENDM

mNEW MACRO ClassName,Objects:VARARG
LOCAL tClass,b1,b2,line
tClass TEXTEQU <ClassName>
b1 TEXTEQU <(>
b2 TEXTEQU <)>

ifidn tClass,<>
exitm
else
FOR arg,<Objects>
line TEXTEQU <>
line CATSTR line,<mov arg,new b1 tClass b2>
%line
ENDM
endif
endm

mVAR MACRO VarType,Objects:VARARG
LOCAL tVariable,line
tVariable TEXTEQU <VarType>

ifidn tVariable,<>
exitm
else
FOR arg,<Objects>
line TEXTEQU <>
line CATSTR line,<tVariable arg>
%line
ENDM
endif
endm


i find it very usefull for less coding.

examples:


1.mINIT CWindow,ecx,0,m_hInstance,m_WindowProc,m_Style,m_Color,m_ClassName,m_AppName

2.mCOPY CWindow,ebx,ecx,m_hInstance,m_WindowProc,m_Style,m_Color,m_ClassName,m_AppName

3.mNEW CFont,obj,obj1,obj2

4.mVAR long,m_dwExStyle,m_lpClassName,m_lpWindowName,m_dwStyle,m_x,m_y
Posted on 2004-09-09 08:52:33 by wizzra