Board index » delphi » Passing COM objects between COM objects

Passing COM objects between COM objects

Greetings Everyone,

My problem is about passing a COM object between COM objects. Here are the
details:

There are three COM objects registered in COM+: CUser1, CUser2 and CDb. All
are created using CreateOleObject() and used as Variants.

The requirement is: CUser1 is invoked from some application. CUser1 creates
CDb and uses it successfully. Then, in the same procedure, it wants to pass
the CDb to CUser2 and let CUser2 use the same object and release it.

At this point, if I call a method of CUser2 and supply CDb as a parameter,
CUser2 can successfully use CDB, no problem in this case.
But this is the case it fails: I supply CDb in a method call of CUser2,
store the reference of CDb as a variant in CUser2. After the method returns,
I call another method of CUser2 and try to use the CDb that has been
assigned to a private field of CUser2 in the previous call. It immediately
destroys the objects and the client gives an "Invalid variant operation"
error. I don't want to supply the CDb in every call, so I somehow need to
store the reference of CDb in CUser2 across calls.

I've debugged it a lot, disbled JIT in order CDb to stay up. I tried
OleVariants instead of Variants, but it still don't work.

I'd very much appreciate a solution. Thanks in advance.

-Gazihan

 

Re:Passing COM objects between COM objects


Btw, I'm also checking the VarType() of the Variant of the object against
varEmpty and varNull. It always is 16396 ($400C), even in the scenario with
no problems. I believe this number has something to do with my interface.

So, Empty or Null Variant is not the reason for my problem. Any comment will
be highly appreciated.

-Gazihan

Quote
"Gazihan Alankus" <gazihan.alan...@ceng.metu.edu.tr> wrote in message

news:3e81b719@newsgroups.borland.com...
Quote
> Greetings Everyone,

> My problem is about passing a COM object between COM objects. Here are the
> details:

> There are three COM objects registered in COM+: CUser1, CUser2 and CDb.
All
> are created using CreateOleObject() and used as Variants.

> The requirement is: CUser1 is invoked from some application. CUser1
creates
> CDb and uses it successfully. Then, in the same procedure, it wants to
pass
> the CDb to CUser2 and let CUser2 use the same object and release it.

> At this point, if I call a method of CUser2 and supply CDb as a parameter,
> CUser2 can successfully use CDB, no problem in this case.
> But this is the case it fails: I supply CDb in a method call of CUser2,
> store the reference of CDb as a variant in CUser2. After the method
returns,
> I call another method of CUser2 and try to use the CDb that has been
> assigned to a private field of CUser2 in the previous call. It immediately
> destroys the objects and the client gives an "Invalid variant operation"
> error. I don't want to supply the CDb in every call, so I somehow need to
> store the reference of CDb in CUser2 across calls.

> I've debugged it a lot, disbled JIT in order CDb to stay up. I tried
> OleVariants instead of Variants, but it still don't work.

> I'd very much appreciate a solution. Thanks in advance.

> -Gazihan

Other Threads