Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now
- - - - -

asBSTR and bstr

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Ped Xing   Members   

122
Like
0Likes
Like

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:
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;
}


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?

#2 jetro   Members   

144
Like
0Likes
Like

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

#3 Gyrbo   Members   

187
Like
0Likes
Like

Posted 27 July 2004 - 05:58 AM

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




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.