RetroForum Welcome, Guest. Please login or register.
March 11, 2010, 11:47:49 AM
Home Help Search Calendar Login Register

RetroForth Discussion  |  Older Boards  |  Bugs  |  Topic: problems using dll calls « previous next »
Pages: 1 Go Down Print
Author Topic: problems using dll calls  (Read 2986 times)
RogerLevy
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 55


View Profile
problems using dll calls
« on: November 25, 2004, 02:14:59 AM »

i'm trying to bind to the Allegro game library from Retro.
first thing is to get the initialization func working - the call i want to make would be the equivilant of, in C:

install_allegro(0,&errno,0); \\ i think! been a long time since i've used C

here's my retroforth code. these lines work just fine:

" alleg40.dll" LoadLibraryAs allegro
allegro " install_allegro" MapFunctionAs install_allegro
variable errno

but it crashes here:

0 errno 0 3 install_allegro invoke

am i doing something wrong?
« Last Edit: November 25, 2004, 02:16:09 AM by RogerLevy » Logged
crc @ work
Guest


Email
Re:problems using dll calls
« Reply #1 on: November 25, 2004, 06:08:33 AM »

Try this:

Code:
" alleg40.dll" LoadLibraryAs allegro
allegro " install_allegro" MapFunctionAs install_allegro
variable errno

install_allegro 0 errno 0 3 invoke

The function name should preceed arguments (I might change this; it'd make some things cleaner. What do you think?)
Logged
RogerLevy
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 55


View Profile
Re:problems using dll calls
« Reply #2 on: November 25, 2004, 08:12:18 AM »

no luck. but this time instead of simply closing itself, i get the standard windows XP "this program encountered a problem and needs to close." message box.

« Last Edit: November 25, 2004, 08:17:09 AM by RogerLevy » Logged
crc @ work
Guest


Email
Re:problems using dll calls
« Reply #3 on: November 25, 2004, 09:06:15 AM »

I'll try to get this working once I get home from work (3-4 hours from now).
Logged
crc @ work
Guest


Email
Re:problems using dll calls
« Reply #4 on: November 25, 2004, 09:07:58 AM »

What does the & in &errno do? I haven't used C in quite a while, so I'm sort of rusty here...
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re:problems using dll calls
« Reply #5 on: November 25, 2004, 11:53:13 AM »

I've tried a lot of approaches, and none seem to work :-( I'll do some reading of the documentation and see if I can find the problem.
Logged
RogerLevy
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 55


View Profile
Re:problems using dll calls
« Reply #6 on: November 25, 2004, 03:39:34 PM »

basically you just have to pass the address of a variable to the function. & is the "address of" operator in C, if i'm not mistaken.

if it will help, i think that the dll doesn't "clean up" after itself, unlike two other DLL's i've used, so it seems to be an oddball. in win32forth i have to DROP all the args plus sometimes the return arg after each call.  maybe it's trying to return to one of its args?
« Last Edit: November 25, 2004, 03:42:16 PM by RogerLevy » Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re:problems using dll calls
« Reply #7 on: November 25, 2004, 03:57:15 PM »

I've attached a custom rf.dll with one new word: cinvoke. This word is used just like invoke, but cleans the stack for you. *sigh* If the Allegro people want to make a DLL, why can't they follow the established methods?

Anyway:

Code:
" alleg40.dll" LoadLibraryAs allegro
allegro " install_allegro" MapFunctionAs install_allegro
variable errno

install_allegro 0 errno 0 3 cinvoke

now works. I'll merge this into the 7.6 codebase, and likely rename 'invoke' in generic_dl to 'cinvoke' for consistency. *sigh* another word to increase the size again...
Logged
RogerLevy
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 55


View Profile
Re:problems using dll calls
« Reply #8 on: November 25, 2004, 04:22:26 PM »

thanks, it worked! although it is a slight approach toward "fathood" i appreciate it alot.

you asked what i thought about the arg order - actually it would be nice if they came before, and perhaps if the function words were self-executing, that would be convenient too. not that the current way is a big deal, imo.
Logged
RogerLevy
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 55


View Profile
Re:problems using dll calls
« Reply #9 on: November 26, 2004, 05:35:36 AM »

btw, i noticed that linking to variables is as easy as using MapFunctionAs on em as if they were functions. then just made sure to @ the resulting created word, and you can @ and ! the address it gives as normal. just thought it would be useful to point out.
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re:problems using dll calls
« Reply #10 on: November 26, 2004, 11:13:59 AM »

Quote
btw, i noticed that linking to variables is as easy as using MapFunctionAs on em as if they were functions. . . . just thought it would be useful to point out.

Thank you for pointing this out, I'll make a note of it in the documentation :-)
Logged
Pages: 1 Go Up Print 
RetroForth Discussion  |  Older Boards  |  Bugs  |  Topic: problems using dll calls « previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC2 | SMF © 2001-2005, Lewis Media Valid XHTML 1.0! Valid CSS!