COM Client / .NET Server with private constructor

  • Thread starter Thread starter Nick Wilton
  • Start date Start date
N

Nick Wilton

Hi guys,

Hope someone here can help. I am performing something almost identical to
the sample shown here, except my .NET server class has a private constructor
and a shared factory method to create an instance of itself.

http://msdn.microsoft.com/library/d...l/cpconcominteropsamplecomclientnetserver.asp

Unfortunately the following lines of code, do not return an interface to my
COM client:

HRESULT hr = CoInitialize(NULL);
IClassPtr pIClass(__uuidof(Class));

What do I need to do in C++/COM in order to get around this problem.
Changing the design of my .NET class is not an option for me.

Thanks in advance,
 
Here,
http://msdn.microsoft.com/library/d.../cpconqualifyingnettypesforinteroperation.asp,
at MSDN documentation you can read:


" Types must have a public default constructor to be activated from COM.
Managed, public types are visible to COM. However, without a public default
constructor (a constructor with no arguments), COM clients cannot create the
type. COM clients can still use the type if it is activated by some other
means. "

You always can have a public class with a public constructor and a method
that returns an new instance of your class. You must put one internal
constructor in your current class which only would be callable from inside
your assembly.


--
Un saludo
Rodrigo Corral González [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org
 
Back
Top