Re: DLL Exports, determine Arg types and RetVal?




Annie wrote:
I hope you're better at programming than you are at ASCII art...
but I wouldn't bet the farm on it. Hehehe!

I didn't want a pointy honker to draw attention away from your beepers.
;)

Here is a simple and limited demonstration of how to create objects
that contain other objects (usefull for cascading menus, filesystem
listings, etc.). Let's see you duplicate this with your fancy-schmancy
DOSsy 'embler:

// runs on Linux and Windows
program container;
#include( "stdlib.hhf" );

type
can:
class
var
x :dword;
o :dword[4];
count :dword;
endvar;

procedure create( item:dword ); @returns( "esi" );
method insert( item1:dword );
method inserto( item1:dword );
method destroy;
method showo;
method showtree( indent:string );
endclass;
endtype;

procedure can.create( item:dword ); @nodisplay;
begin create;

push( eax );
if ( esi = 0 ) then
mem.alloc( @size( can ) );
mov( eax, esi );
endif;
mov( &can._VMT_, this._pVMT_ );
mov( item, eax );
mov( eax, this.x );
mov( 0, this.o );
mov( 0, this.count );
pop( eax );

end create;

method can.inserto( item1:dword ); @nodisplay;
begin inserto;

push( eax );
push( ebx );
push( ecx );
mov( item1, eax );
mov( this.count, ebx );
lea( ecx, this.o );
mov( eax, [ecx + ebx] );
add( 4, ebx );
mov( ebx, this.count );
pop( ecx );
pop( ebx );
pop( eax );

end inserto;

method can.insert( item1:dword ); @nodisplay;
begin insert;

push( eax );
push( ebx );
push( edx );
push( esi );
push( edi );
lea( ebx, this.o );
mov( this.count, edx );
mov( item1, eax );
can.create( eax );
mov( esi, [ebx + edx] );
add( 4, edx );
pop( edi );
pop( esi );
mov( edx, this.count );
pop( edx );
pop( ebx );
pop( eax );

end insert;

method can.showo; @nodisplay;
begin showo;

stdout.puti32( this.x );
stdout.newln();
if (this.count != 0) then
push( ecx );
for ( mov( 0, ecx ); ecx < this.count; add( 4, ecx ) ) do
push( esi );
push( edi );
push( ebx );
lea( ebx, this.o );
add( ecx, ebx );
mov( [ebx], esi );
(type can [esi]).showo();
pop( ebx );
pop( edi );
pop( esi );
endfor;
pop( ecx );
endif;

end showo;

method can.showtree( indent:string );
var
s: string;
c: byte[256];

begin showtree;

push( eax );
str.init( c[0], 256 );
mov( eax, s );
str.cpy( " ", s );
str.cat( indent, s );
stdout.put( s );
stdout.puti32( this.x );
stdout.newln();
if (this.count != 0) then
push( ecx );
for ( mov( 0, ecx ); ecx < this.count; add( 4, ecx ) ) do
push( esi );
push( edi );
push( ebx );
lea( ebx, this.o );
add( ecx, ebx );
mov( [ebx], esi );
(type can [esi]).showtree( s );
pop( ebx );
pop( edi );
pop( esi );
endfor;
pop( ecx );
endif;
pop( eax );

end showtree;


method can.destroy; @nodisplay;
begin destroy;

if (this.count != 0) then
push( ecx );
for ( mov( 0, ecx ); ecx < this.count; add( 4, ecx ) ) do
push( esi );
push( edi );
push( ebx );
lea( ebx, this.o );
add( ecx, ebx );
mov( [ebx], esi );
(type can [esi]).destroy();
pop( ebx );
pop( edi );
pop( esi );
endfor;
pop( ecx );
endif;
if ( isInHeap( esi ) ) then
mem.free( esi );
endif;

end destroy;

readonly
VMT( can );
endreadonly;

var
mycan :can;
temp1 :pointer to can;
temp2 :pointer to can;
temp3 :pointer to can;
temp4 :pointer to can;
temp5 :pointer to can;
temp6 :pointer to can;
endvar;

begin container;

can.create( 1 );
(type can [esi]).insert( 2 );
(type can [esi]).insert( 3 );
(type can [esi]).insert( 21 );
(type can [esi]).insert( 22 );
mov( esi, temp1 );
can.create( 4 );
(type can [esi]).insert( 5 );
(type can [esi]).insert( 6 );
mov( esi, temp2 );
can.create( 7 );
(type can [esi]).inserto( temp1 );
(type can [esi]).inserto( temp2 );
mov( esi, temp5 );
stdout.put( "Contents of 'temp5':", nl );
stdout.put("--------", nl );
(type can [esi]).showo();
stdout.put("--------", nl );

can.create( 11 );
(type can [esi]).insert( 12 );
(type can [esi]).insert( 13 );
mov( esi, temp3 );
can.create( 14 );
(type can [esi]).insert( 15 );
(type can [esi]).insert( 16 );
(type can [esi]).insert( 23 );
(type can [esi]).insert( 24 );
mov( esi, temp4 );
can.create( 17 );
(type can [esi]).inserto( temp3 );
(type can [esi]).inserto( temp4 );
mov( esi, temp6 );
stdout.put( "Contents of 'temp6':", nl );
stdout.put("--------", nl );
(type can [esi]).showo();
stdout.put("--------", nl );

mycan.create( 8 );
mycan.inserto( temp5 );
mycan.inserto( temp6 );
stdout.put( "All objects:", nl );
stdout.put("--------", nl );
mycan.showo();
stdout.put("--------", nl );
stdout.put( "The Tree:", nl );
stdout.put("--------", nl );
mycan.showtree( "" );
stdout.put("--------", nl );
mycan.destroy();

end container;

Nathan.

.



Relevant Pages