The idea is to create some add-on in a program using COM functions interface exist in his own API.

The particular type which I try to implement is a generic one , let say MyClass, and is declared like below:
//MyClassPtr declaration;
_COM_SMARTPTR_TYPEDEF(MyClass, __uuidof(IDispatch));

//The class itself
struct __declspec(uuid("5e772660-389b-11ce-ba48-080036250302"))
MyClass : IDispatch
{
...
// other functions...
...
IDispatchPtr Function1;
__declspec(property(get=GetArea,put=PutArea))
IDispatchPtr Function2;
__declspec(property(get=GetSize))
...
}

I create an instance of MyClass using:
MyClassPtr pMyInstance;

This pMyInsatance have to be provided to another API function but in form of a SAFEARRAY!This function can look like below:

FinalFunction(SAFEARRAY * * pMyClassInstances, .. , ..)

So I have to convert my variable MyClass (can be more than one in my code of course, but I want to limit only to one instance for now) to this SAFEARRAY .. How can I do this?

I try:
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = 1;
long a=0;

SAFEARRAY * vMyClassArray;
vMyClassArray.vt = VT_VARIANT|VT_ARRAY;
vMyClassArray= SafeArrayCreate(VT_VARIANT, 1, rgsabound);
SafeArrayPutElement(vMyClassArray .parray, &a, &(pMyInstance));

Finally I put my class instance as an argument for:
FinalFunction(pMyInstance, .. , ..)

It doesn't seem to work, probably because argument pMyInstance can not be express as a VARIANT declarated type.
The class I want to work with - MyClass- which exist in a .tlh file, is part of the API interface, so it is not exactly a user define type, but more an interface define type. I mention this becose I try to work with VT_RECORD type in SafeArrayCreate(...) instead of VT_VARIANT type, but this imply an idl function declaration for my type, and other additional stuff

Any ideea ??