Hi all,

Im trying to work on some networking stuff. I've added some procedure declarations that BinarySoup made to w.hhf. I'm having problems declaring a variable as WSADATA. Im still new to ASM in general. What am I doing wrong?

Thanks.




program fileOutput;
#include ("stdlib.hhf")
#include ("w.hhf")

static
oWsadata:WSADATA;

begin fileOutput;

call (WSAStartup, $0002h, &oWsadata);

end fileOutput;
Posted on 2004-12-13 07:23:23 by polyfractal
Hi,



oWsadata:WSADATA;

WSADATA is into the namespace w so you must write w.WSADATA and no WSADATA (see w.hhf).



call (WSAStartup, $0002h, &oWsadata);

function call is like C language. The call statment is only when you push args on the stack before calling your function. You can't mix them.
no need to add 'h' suffix to hex literal

Ok, WSADATA is declared in w.hhf but not the WSAStartup function, you have to put its signature at the beginning.

Here is the code



program fileOutput;
#include ("stdlib.hhf")
#include ("w.hhf")

static
WSAStartup: procedure
(
wVersionRequested: word;
var lpWSAData: w.WSADATA
);
@stdcall;
@returns( "eax" );
@external( "__imp__WSAStartup@8" );

WSACleanup: procedure;
@stdcall;
@returns( "eax" );
@external( "__imp__WSACleanup@0" );

static
oWsadata: w.WSADATA;

begin fileOutput;

WSAStartup( $0002, &oWsadata );
...
WSACleanup();

end fileOutput;


to compile and link, type
hla wsatest.hla ws2_32.lib

ws2_32.lib is coming from the masm32 package that you can download at www.masm32.com. Once installed, you'll found ws2_32.lib into the lib directory.

that's all and sorry for my bad english
Posted on 2004-12-13 18:48:32 by arlequin
Hi. Thanks for the help, it is working great now.

Another question though. How do I print out the szDescription field? I know it is a null terminated string that can be up to 256 characters, but how do i convert that to a printable form?

Here is my code, which explodes with a memory access violation.

Thanks again for the help!



stdout.put(( type word oWsadata.wVersion ), nl);
stdout.put(( type word oWsadata.wHighVersion ), nl);
stdout.put(( type string oWsadata.szDescription ), nl); <--This line
Posted on 2004-12-14 06:54:27 by polyfractal
Hi,



stdout.put(( type string oWsadata.szDescription ), nl);

The problem is that stout.put() expect a pointer to a HLA String and not a pointer to a null terminated string. There is a description of HLA String at http://webster.cs.ucr.edu/AoA/Windows/HTML/CharacterStrings.html#999809. Read it carefully because almost all string handling routines in the HLA Standard Library use HLA String.

Some routines of the HLA Standard Library allow to interact with null terminated string.



static
description: str.strvar(256); // the storage is statically allocated

begin ...
...
str.cpyz( oWsadata.szDescription, description );
stdout.put( "Description: ", description, nl );
...


if you don't want to allocate statically 256 bytes of storage



static
description: string;

begin ...
...
// returns a pointer to the new HLA string in eax
str.a_cpyz( oWsadata.szDescription ); // heap allocation
mov( eax, description );
stdout.put( "Description: ", description, nl );
...
strfree( description ); // free heap alloc
...


Yeah, HLA is really cool ! 8)
Posted on 2004-12-14 17:31:42 by arlequin