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
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?
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;}
The problem is the bstr has an extra dword at the start with the size of the string. You have to use BstrAlloc() to create an asBSTR
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement