A previous experiment, and subsequent failure can be found here:
http://www.c-sharpcorner.com/Forums/ ShowMessages.aspx?ThreadID=49016
verb/Create_Player(var/n as num)
if(call("R_Controller.dll","CreatePlayer")(n))
usr<<"Player [n] created successfully."
verb/List_Players()
var/s = call("R_Controller.dll","ListPlayers")()
usr << s
In the code above, Create_Player works as expected. However,
I haven't been able to get List_Players() to work. In its present form (below) it crashes dream seeker. However, I have had a variation which merely spits out "est " instead of "test" (when passed to string2return), and another, returned a bunch of incoherent symbols (which looked like strange letter 'i').
extern "C" R_CONTROLLER_API char *ListPlayers()
{
static char string2return[500];
*string2return=0;
for( map<int, Player*>::iterator i=listOfPlayers.begin(); i != listOfPlayers.end(); i++)
{
strncat(string2return, (char*)(i->first), __min( 20, 500-strlen(string2return)) );
//params: char array, char array to append, number of chars to append
//__min returns the lesser of 2 numbers
}
return string2return;
}
I'm having no luck with strings or char arrays being passed to byond (I hate char arrays). I also hate C++, but it's the language of choice for what I'm attempting.
Any light that can be brought to this nether region of my brain would be most appreciated.
While I could hunt through that snippet for subtle logic errors that accompany your off-by-one error (string2return should have 501 elements to account for the possibility of that last terminating NUL byte), I'm going to go for another riddle instead.
You should show the definition CreatePlayer(). I'm assuming that the first element in the map is a pointer to a character array (key maybe?), but your DM code seems to make it appear as a simple number, so I don't understand why you're casting it as a char pointer in List_Players(), as (char*)45 doesn't exactly result in "45". Maybe you're looking for the itoa() standard C function.