News:

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

Including Libraries (Beginner's question..)

Started by m0nk3yi3unz, July 04, 2009, 02:58:38 AM

Previous topic - Next topic

m0nk3yi3unz

Hey all. First post, hopefully not my last :) I've taken a keen interest in MASM32, and now HLA (I love writing network applications - anything with sockets just absolutely fascinates me). With the constant annoyance of the fact that everything having to do with any ASM language is completely under-supported, so this forum should quench my knowledge thirst!

I just started HLA today; first thought was that it's idea was pointless, till I realized breaking down conversion methods in ASM was a thing of the past! (Among other things!) So I thought I'd give it a try.

However, I'm having a bit of difficulty - In MASM, including a library file was as easy as using the "includelib" command - however, I'm having trouble finding an equivalent for HLA. I have an updated header file (winsock.hhf), however I suspect I need the library file (1, because I did in MASM, and 2, the type WSADATA turns blue in radasm (depicting a valid type), however upon compile it says it can't find that type [or something along those lines]).

Just in case I have an error or whatnot, I'll post my code and my makefile for help (because I'm sure I'm missing something).

HLATesting.hla:

program HelloWorld;

#include( "stdlib.hhf" )
#include( "wsock32.hhf" )
#include( "kernel32.hhf" )

var
outsock:WSADATA;
endvar;


begin HelloWorld;

xor(eax,eax);

try
WSAStartup($101,&outsock); // I'm sure I have something wrong
// with this: $101 should be a hex value,
// &outsock is a pointer to the variable
// declared at the top (and I read that
// & before it makes it a pointer).

WSACleanup();
endtry;

ExitProcess(0);
end HelloWorld;


Makefile

build: HLATesting.obj

buildall: clean HLATesting.exe

compilerc: HLATesting.res

syntax:
hla -s HLATesting.hla

clean:
del *.exe
del *.obj
del *.res
del *.link
del *.asm
del *.map

HLATesting.res: HLATesting.rc
rc /v HLATesting.rc

HLATesting.obj: HLATesting.hla
hla $(debug) -c HLATesting

HLATesting.exe: HLATesting.hla
hla $(debug) HLATesting


I'm sure I have something wrong with the code - in the HLA source, the second parameter for WSAStartup has to be a pointer. I know this for a fact, and in MASM, I (if I remember right) just had to enclose it with brackets. I'll look up pointers here again, just to make sure.

But again, my main problem is that I'm pretty set on getting that darn library included!

Thanks!!

-Monkey

d0d0

Hi m0nk3yi3unz,

Welcome to the forum. In terms of MASM you're in the right place. The HLA subforum is kinda dead - most of the action is on the yahoo group aoaprogramming.

Have you setup your environment properly i.e. I think hla uses the hlalib environment variable to search for libraries.

There should be a  wsock32.lib with the hla distribution - hla\hlalib


Evenbit

This is a common issue when us coders explore the Win32 API functions beyond the most common set.  HLA generates a standard "*.link" linker-response file that looks like this:
-heap:0x1000000,0x1000000
-stack:0x1000000,0x1000000
-base:0x4000000
-entry:HLAMain
-section:.text,ER
-section:.data,RW
-section:.bss,RW
kernel32.lib
user32.lib
gdi32.lib

You will want to add "wsock32.lib" (or whatever) to the bottom of that list.  Then use the "-@" switch to keep HLA from deleting your "*.link" file and creating its own.

Nathan.

m0nk3yi3unz

Thanks for the warm welcome :)

@d0d0 - I'll definitely look up that group, as I can guarantee you I'll need help in the future ;)

Yes, I have the library, it's just getting my script to recognize it.


@Evenbit - Alright, I tried it, however it didn't fix the problem :X

I took out the try statement (because it was an error - I didn't look for an exception, so instead of implementing exception handling, I just took it out to get it to work initially). However, I'm still getting an error, and things look like they -should- work, however I'm not getting any soup...

New code:


program HelloWorld;

#include( "stdlib.hhf" )
#include( "wsock32.hhf" )
#include( "kernel32.hhf" )

var
outsock:WSADATA;
endvar;


begin HelloWorld;

xor(eax,eax);
WSAStartup($101,outsock); // Removed the & for testing... Less errors :X

WSACleanup();

ExitProcess(0);
end HelloWorld;


and I get (from compiling with hla - just the hla file - and the "-@" delimiter):
Quote
Error in file "HLATesting.hla" at line 8 [errid:51766/hlaparse.bsn]:
Undefined symbol.
Near: << WSADATA >>

Error in file "HLATesting.hla" at line 15 [errid:59510/hlaparse.bsn]:
Undefined symbol.
Near: << outsock >>


In the meantime, I'll consult the yahoo group. Do note that I do have the library included just like Evenbit instructed, so the error has to be in the code itself. Like I said, it looks right, but perhaps I'm missing something? :X

Thanks for the quick replies!

-Monkey

Evenbit

First, if you are not using any StdLib functions, then there is no need to include its header in your program.

Second, when using the Win32 API functions, you will want to include the "w.hhf" header file which will define those symbols {and other things} for you.

program HelloWorld;

#include( "w.hhf" )

var
...


Nathan.

m0nk3yi3unz

Bleh, I just realized, the include command at the top isn't working. When i c/p the WSADATA record type info into the main source file, bypassing the header file, It worked just fine.

Regardless, I think I'm just going to stick with MASM. I couldn't even get the MessageBox API to work - period. Every time I ran the program I got a File Write Exception - and I wasn't using ANY file IO operations whatsoever. Kinda ridiculous HLA would include exception stuff like that - wastes space in my opinion, and it's one of the reasons why I decided to move on from C#. The whole built in exception thing in a low-level (well, HLA level... the medium level...) is hoaky IMO. Not to mention compiling from HLA to Masm source is just ridiculous to even try to use.

It's a good idea, HLA, but just doesn't execute properly (no pun intended!).

Thanks for the prompt answers! I'm sure you'll see me on the MASM end of this forum from now on :)

Cheers!

-Monkey

Evenbit

So, when you can't get a MessageBox API program to work in MASM, are you going to blame MASM for your failures too??  Are you going to start spreading lies about MASM simply because you don't have the patience to properly debug your code??

Nathan.

m0nk3yi3unz

...? Excuse me? I've already written a complete winsock server in MASM ;) I've made many-a message-box. I was trying HLA to see if it yielded any significant advantages - none, so far, prominent enough to make me hold on to it ;)

In the future, please don't bash me? Yes, I'm still new to MASM, but not to the rest of the programming world. I'm proficient in C++ and (god forbid) C#, along with almost every major online language. So no, I'm not giving up when MASM doesn't go as planned - however, like I said, I don't like the built in exception handling HLA did.

If you still don't believe I know how to do API's in MASM, I'll prove it to you. I was hoping this forum wouldn't be like that... but whatever. I guess you can't find a perfect forum these days?

-Monkey

P.S.: Did I once spread a lie about HLA? No, I don't think so. So pardon me when I say I don't want to continue hardcore learning a language that doesn't suit my needs...

Sevag.K

Exception handling in HLA is small, efficient and totally optional; and hla does manage to execute properly for most of its users, strangely enough.


d0d0

Hey m0nk3yi3unz,

Try not to give up too easily :wink.  I had the same problems when i got started with hla. most of the features you don't use can be turned off. IMHO the tiny abstraction above pure asm that it provides allows you to write some serious robust applications. I'm not saying that can't be done in assemblers like masm,fasm etc. It's just much easier.

Randy did start an online book on windows programming in hla. there are pdfs on the various apis in hla syntax and you can also find Iczelion's tutorials converted to hla here:
http://webster.cs.ucr.edu/Page_win32/index.html

HLA is huge language but you can still use it without the high level stuff

m0nk3yi3unz

@Sevag.K - Perhaps I have a strange version? Again, it gives me a file write error when I don't use anything close to a FileIO function call. :/

@d0d0 - I know, it's just I haven't gotten one script to work for me in HLA yet - just when I think I have just the basics down, something completely unexpected happens. On top of that, there is hardly -any- support for HLA :X

Thanks for the link though - I've been to that site many times, though i haven't found that particular page yet. It should prove to be useful!

I'll keep trying everyone - just been a frustrating start ;)

Cheers!

-Monkey

Sevag.K

Quote from: m0nk3yi3unz on July 07, 2009, 05:03:01 PM
@Sevag.K - Perhaps I have a strange version? Again, it gives me a file write error when I don't use anything close to a FileIO function call. :/

Are you sure you didn't use stdout.put ?
How about posting the code so we can see what's going on?  If you found a bug with HLA, it would help the author.

For the code you did post, I did a quick edit of your source and found a couple of bugs: you try to reference the address of a var (stack) object using the static address notation '&' and you forgot to include an exception clause.



program HelloWorld;

// build using: hla <filename> wsock32.lib

#include( "stdlib.hhf" )
#include( "w.hhf")

static
    WSAStartup : Procedure
    (
            wVersionRequired: DWORD;
            lpWSAData: DWORD
    );
    @stdcall;
        returns( "eax" );
        external( "__imp__WSAStartup@8");

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


outsock :dword[4];  // changed to static object, I'm too lazy to write in the fields of wsadata


begin HelloWorld;

xor(eax,eax);

try
WSAStartup($101, &outsock);
WSACleanup();

anyexception; 
               // if you use the exception handler, you need somewhere to go if an exception occurs.
endtry;

w.ExitProcess(0);
end HelloWorld;


m0nk3yi3unz

Yea, as for the try statement, I knew I had to have the exception handling part of it - I just didn't have it in the version I put in the first code (since my question was initially about adding libraries to the build).

And after reading d0d0's link, the code you posted makes sense now :) I see how HLA works.

I'll keep going on it - I'm sure I'll figure it all out soon.

Thanks for all the replies! :)