Using SAFEARRAYs in C++ isn't that easy, but our classes in tsvcutil.h do make it a little easier.
The following should work:
TSUTIL::SafeArray<> objectsToSerialize;
std::vector<TS::PropertyObjectPtr> objectsToSerializeVector;
objectsToSerializeVector.push_back(yourResultObject);
objectsToSerialize.SetFromVector(objectsToSerializeVector);
engine->SerializeObjects(...objectsToSerialize.Get()...);
Then on the unserialize side you can do something like:
TSUTIL::SafeArray<> safeArray(engine->UnserializeObjectsAndTypes(...)); // safeArray will take ownership of the SAFEARRAY object and destroy it automatically in its destructor when it goes out of scope
std::vector<TS::PropertyObjectPtr> unserializedObjects;
safeArray.GetVector(unserializedObjects);
// You might want to check unserializedObjects.size() before accessing it to make sure that there are the number of objects you are expecting.
ASSERT(unserializedObjects.size() == 1); // just an example of checking the size. you might want to do it explicitly with an 'if' statement rather than in an assert.
TS::PropertyObjectPtr myResultObject = unserializedObjects[0];
Edited message: *sigh*, the forum turned some of the code into smiley faces the smiley faces are really a ':' character followed by a 'P' character. Sorry not sure how to tell the forum to leave that text alone.
-Doug
Message Edited by dug9000 on
02-21-2008 10:43 AM