Message Board


Message Board > Fenix / Bennu / Gemix / DIV > Fenix DLL questionisms

July 12, 2007, 23:28
OScoder
None
1338 posts
Hi,
I'm currently experimenting with making dlls for fenix (I got a simple dev-cpp project working!). Why is it I can find no documentation of the dll-api whatsoever (I'm using fenix 0.92a)? For what I want to do to work, I need to be able to call a process/function from the game that imports the dll - is there any way to do this (I won't say what for yet :P )? Also, do all exported functions have to be declared as type "static int", or is it possible to declare others?

Thanks,
OScoder
____________
om
#
July 13, 2007, 01:11
Moogle
Enterprise Edition
239 posts

*Moogle patiently waits for a big Sandman reply
____________
I am Moogle and I approve this message.

Quoting (. )( .) in the Bugs topic:
Everytime I login the threads with new posts are by Dennis.
#
July 13, 2007, 10:01
Quiest
now with more happynes
142 posts

I`d also like some info on writing and using dlls for/in Fenix. Sandyman?
____________
Roundhousekick to the face, baby!
#
July 13, 2007, 12:38
Dennis
どこかにいる
2092 posts

Quoting OScoder:
Hi,
I'm currently experimenting with making dlls for fenix (I got a simple dev-cpp project working!). Why is it I can find no documentation of the dll-api whatsoever (I'm using fenix 0.92a)? For what I want to do to work, I need to be able to call a process/function from the game that imports the dll - is there any way to do this (I won't say what for yet :P )? Also, do all exported functions have to be declared as type "static int", or is it possible to declare others?

Thanks,
OScoder
You could download Sandman's Network.dll and look at his code to see how he does it. It will be a good idea to put on the fenix wiki. have you checked http://fenix.itlodge.net yet?
____________
Kwakkel
#
July 13, 2007, 12:46
Fiona
games are terrible
-9616558 posts

Quoting Moogle:
*Moogle patiently waits for a big Sandman reply


You remember how whenever Slainte used to post on div-arena it was always a bunch of technical gobbldy-gook that no one in the world understood?

I have a feeling Sandman will end up like that one day.
____________
laffo
#
July 13, 2007, 14:03
Dennis
どこかにいる
2092 posts

strange people they become

they even allocate the memory in their caddy when they go to the super market.
____________
Kwakkel
#
July 13, 2007, 16:57
Rincewind
programmer
1545 posts

Quoting OScoder:
Why is it I can find no documentation of the dll-api whatsoever (I'm using fenix 0.92a)?

Probably because there is no documentation for that.

Quoting OScoder:
For what I want to do to work, I need to be able to call a process/function from the game that imports the dll - is there any way to do this (I won't say what for yet )?


It is possible to call processes/functions from the game in the dll, however as far as I know it's impossible to use parameters.

Code:
     INSTANCE * proc = instance_new (procdef_get(/* process_type here */), first_instance); 
     return instance_go (proc); 


With /* process_type here */ being whatever value Fenix returns for "type my_process".

[Edited on July 13, 2007 by Rincewind]
____________
Personal website: http://www.loijson.com
#
July 23, 2007, 13:03
Sandman
F3n!x0r
1194 posts

Oh yes. Hmm. I must make some documentation.
It'll be on the Wiki sometime. ;)

In the meantime, looking at NetworkDLL.c is a fine way, indeed.

[EDIT]
Done: http://fenixdocs.com/index.php?title=Making_DLLs

I need someone to beta test it! If something doesn't work, be so kind as to contact me so I can alter the setup. Or just post your findings here or on the discussion page.

[Edited on July 23, 2007 by Sandman]
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
August 24, 2007, 01:36
Sandman
F3n!x0r
1194 posts

Sooo...any findings?

And OScoder, how's it coming along?
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
August 25, 2007, 20:45
link3rn3l
Whiskered
78 posts
please try VC++ express is very easy develop DLLs in win32

bye,
____________
#
September 4, 2007, 12:24
OScoder
None
1338 posts
Quote:
And OScoder, how's it coming along

It's working alright - I've got fenix calling some functions in the dll, but I haven't worked on it for a while. Btw, I've been wondering: how hard would it be to write an open-gl/direct X wrapper for fenix? Another idea I've had is writing a wrapper creator that does automatic code generation for a wrapper dll, but that's a little beyond me, I think! Right now I'm writing a wrapper for LUA, so I can use LUA scripts in my games.

OScoder
____________
om
#
September 4, 2007, 20:58
Sandman
F3n!x0r
1194 posts

An OpenGL wrapper wouldn't be all that hard. Somewhere in the future I was planning on doing this. Well not a wrapper, but more a system working like Fenix, but using OpenGL.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
November 14, 2007, 22:23
OScoder
None
1338 posts
Hi,
I have yet one more question on fenix dll coding! Is it possible (and if so, how?) to return a string from a dll function?

Thanks,
OScoder
____________
om
#
November 15, 2007, 00:37
Sandman
F3n!x0r
1194 posts

Yes.

Code:
static int NET_VERSION (INSTANCE * my, int * params)
{
    int r = string_new(NETversionreply);
    string_use(r);
    return r;
}

and
Code:
FENIX_export ("NET_VERSION",            "",        TYPE_STRING,    NET_VERSION                ) ;


string_new(const char * ptr) tells Fenix to make a new string with the specified content and it returns the stringID.
string_use(int code) tells Fenix the string should be kept after this function ends.

So then you just return the stringID and don't forget to put TYPE_STRING in the FENIX_export().
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
November 17, 2007, 15:48
OScoder
None
1338 posts
Does this look right?
Code:
static int LUA_GET_STRING(INSTANCE *my, int *params)
{
 SCRIPT_ID id = (SCRIPT_ID)params[0];
 int index = (int)params[1];
 const char *s = get_string(id, index);
 int r = string_new(s);
    string_use(r);
    free((void*)s);
 return(r); 
}

Code:
FENIX_export("LUA_GET_STRING", "IW", TYPE_STRING, LUA_GET_STRING);


I'm trying to locate a bug I mentioned in the worklog: does this code look clean? (if so, it'll be in my LUA code, and I'll start a new thread)

Thanks,
OScoder
____________
om
#
November 17, 2007, 19:30
link3rn3l
Whiskered
78 posts
http://rapidshare.com/files/30617934/Dll.zip.html

examples included

fenixpack too include DLLS with sources

[Edited on November 17, 2007 by link3rn3l]
____________
#
November 17, 2007, 22:53
Sandman
F3n!x0r
1194 posts

I checked the Fenix source and it uses strdup() on the string, so you can indeed free the string. This implies that get_string() is probably faulty and you should check that (and that the string has a terminating character at the end).

[EDIT]

Also, that bug in the worklog looks like the string is not terminated by a NULL character, make sure it is.

[Edited on November 18, 2007 by Sandman]
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
November 18, 2007, 17:04
OScoder
None
1338 posts
Quote:
Also, that bug in the worklog looks like the string is not terminated by a NULL character, make sure it is.

That'll be it. For some reason, the function in the lua api that gives string length doesn't include the NULL.

This fixes it:
Code:
    string_length = lua_objlen(state, index);
    ret_string = malloc(string_length + 1);        /*allocate memory for return string (so it doesn't get destroyed by LUA's garbage collector)*/
    strcpy(ret_string, lua_tolstring(state, index, &string_length)); /*copy string returned by LUA to our temp return string*/
    ret_string[string_length + 1]='\0';


I'm not doing anything in a bad way here am I?

Thanks again,
OScoder

[Edited on November 18, 2007 by OScoder]
____________
om
#
November 18, 2007, 17:17
Sandman
F3n!x0r
1194 posts

Well if you just add 1 to the 'length of the string', without specifying that last character, it doesn't have to be NULL at all. So you can only do this if you also make sure it is NULL.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
November 18, 2007, 17:20
OScoder
None
1338 posts
You replyed too fast, lol. I've just done that! (and edited above) The LUA docs do say that there'll be a NULL at the end of any string given, which is strange, since they don't seem to!

[Edited on November 18, 2007 by OScoder]
____________
om
#
November 18, 2007, 19:21
link3rn3l
Whiskered
78 posts
new fenix DLL creation Guide
available in :

http://fenixpack.blogspot.com/




..
____________
#

Message Board > Fenix / Bennu / Gemix / DIV > Fenix DLL questionisms

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!