asBSTR* TimeString()
{
char buffer[100];
if (game.min < 10)
{
if (game.sec < 10) sprintf(buffer, "0%d'0%d", game.min, game.sec);
else sprintf(buffer, "0%d'%d", game.min, game.sec);
} else {
if (game.sec < 10) sprintf(buffer, "%d'0%d", game.min, game.sec);
else sprintf(buffer, "%d'0%d", game.min, game.sec);
}
return (asBSTR*)buffer;
}
asBSTR and bstr
Started by Ped Xing, Jul 27 2004 04:40 AM
2 replies to this topic
#1 Members - Reputation: 122
Posted 27 July 2004 - 04:40 AM
I'm having trouble making my script file read a *bstr from my host program.
I define the bstr like so:
asBSTR *timeStr;
I register the bstr like so:
r = engine->RegisterObjectProperty("CGame", "bstr timeStr", offsetof(CGame, timeStr)); assert( r >= 0 );
Then I have a function that returns a Time String:
Then every frame I make game.timeStr = TimeString(); inside of my host. When the player dies I want a script file to print the time that he played. So I do this:
bstr s = "Time: ";
s += game.timeStr;
And it crashes my progam. Any advice?
Ad:
#2 Members - Reputation: 144
Posted 27 July 2004 - 05:43 AM
Here's an example of how I am returning bstr to script code. At least this doesn't crash, hopefully this is correct regarding memory usage as well.
static asBSTR script_Object_getName(Object *o)
{
char *name = o->getName();
asBSTR res = asBStrAlloc(strlen(name));
strcpy((char *)res, name);
return res;
}
--Jetro Lauha - tonic - http://jet.ro






