C++ classes in a COM Interface? 
Author Message
 C++ classes in a COM Interface?

Is it possible to implement C++ classes into a COM interface?
I want to turn my "simple" DLL into a COM component using ATL wizard and MFC
support... I understand how it works with exported functions that I put in
the COM Interface (declare in the idl file, using HRESULT return type etc..)
but can I put C++ classes in my COM Interface? how to do that? How the
member will be accessed from the COM client?


Tue, 21 Sep 2004 01:44:31 GMT  
 C++ classes in a COM Interface?
Creates an ATL project, add a new object. add to object inheritance your
class. It's not easy to done what you ant but you can try.

Mike


Quote:
> Is it possible to implement C++ classes into a COM interface?
> I want to turn my "simple" DLL into a COM component using ATL wizard and
MFC
> support... I understand how it works with exported functions that I put in
> the COM Interface (declare in the idl file, using HRESULT return type
etc..)
> but can I put C++ classes in my COM Interface? how to do that? How the
> member will be accessed from the COM client?



Mon, 20 Sep 2004 16:04:05 GMT  
 C++ classes in a COM Interface?
You cannot pass C++ classes via COM interfaces (if that's what you are
asking). You cannot export C functions in COM either (you certainly can
export functions from a DLL that serves COM objects, but that us not
COM - you are going around it).

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Is it possible to implement C++ classes into a COM interface?
> I want to turn my "simple" DLL into a COM component using ATL wizard and MFC
> support... I understand how it works with exported functions that I put in
> the COM Interface (declare in the idl file, using HRESULT return type etc..)
> but can I put C++ classes in my COM Interface? how to do that? How the
> member will be accessed from the COM client?



Tue, 21 Sep 2004 03:47:43 GMT  
 C++ classes in a COM Interface?
Maybe I was not clear...
If have a dll which is not COM but I need to use this dll into a C#
project...
So I want to turn this Dll into a COM Server and add it as a reference in my
C# project (COM client)...
I know that if I create an ATL project with MFC support I can put my
exported Dll function into the COM Server Interface and use it in my C#
project... of course these functions should be first modified to be COM
compliant (use HRESULT as return data types, create a tlb file for .NET
etc...) but I'd like to know how I can do the same with classes instead of
simple functions...Is it possible to expose a class within a COM interface
instead of functions...? How this class will be handled in the COM client?
Thanks


You cannot pass C++ classes via COM interfaces (if that's what you are
asking). You cannot export C functions in COM either (you certainly can
export functions from a DLL that serves COM objects, but that us not
COM - you are going around it).

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Is it possible to implement C++ classes into a COM interface?
> I want to turn my "simple" DLL into a COM component using ATL wizard and
MFC
> support... I understand how it works with exported functions that I put in
> the COM Interface (declare in the idl file, using HRESULT return type
etc..)
> but can I put C++ classes in my COM Interface? how to do that? How the
> member will be accessed from the COM client?



Tue, 21 Sep 2004 14:43:40 GMT  
 C++ classes in a COM Interface?
I think Alexander has already answered you. You can't expose a class within
a COM interface. You would have to use an interface that the class you want
to expose implements.


Quote:
> Maybe I was not clear...
> If have a dll which is not COM but I need to use this dll into a C#
> project...
> So I want to turn this Dll into a COM Server and add it as a reference in
my
> C# project (COM client)...
> I know that if I create an ATL project with MFC support I can put my
> exported Dll function into the COM Server Interface and use it in my C#
> project... of course these functions should be first modified to be COM
> compliant (use HRESULT as return data types, create a tlb file for .NET
> etc...) but I'd like to know how I can do the same with classes instead of
> simple functions...Is it possible to expose a class within a COM interface
> instead of functions...? How this class will be handled in the COM client?
> Thanks



> You cannot pass C++ classes via COM interfaces (if that's what you are
> asking). You cannot export C functions in COM either (you certainly can
> export functions from a DLL that serves COM objects, but that us not
> COM - you are going around it).

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > Is it possible to implement C++ classes into a COM interface?
> > I want to turn my "simple" DLL into a COM component using ATL wizard and
> MFC
> > support... I understand how it works with exported functions that I put
in
> > the COM Interface (declare in the idl file, using HRESULT return type
> etc..)
> > but can I put C++ classes in my COM Interface? how to do that? How the
> > member will be accessed from the COM client?



Tue, 21 Sep 2004 16:41:18 GMT  
 C++ classes in a COM Interface?
You can use your dll in C# whitout convert it to COM.
Look for .NET Interop Services.



Quote:
> Maybe I was not clear...
> If have a dll which is not COM but I need to use this dll into a C#
> project...
> So I want to turn this Dll into a COM Server and add it as a reference in
my
> C# project (COM client)...
> I know that if I create an ATL project with MFC support I can put my
> exported Dll function into the COM Server Interface and use it in my C#
> project... of course these functions should be first modified to be COM
> compliant (use HRESULT as return data types, create a tlb file for .NET
> etc...) but I'd like to know how I can do the same with classes instead of
> simple functions...Is it possible to expose a class within a COM interface
> instead of functions...? How this class will be handled in the COM client?
> Thanks



> You cannot pass C++ classes via COM interfaces (if that's what you are
> asking). You cannot export C functions in COM either (you certainly can
> export functions from a DLL that serves COM objects, but that us not
> COM - you are going around it).

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > Is it possible to implement C++ classes into a COM interface?
> > I want to turn my "simple" DLL into a COM component using ATL wizard and
> MFC
> > support... I understand how it works with exported functions that I put
in
> > the COM Interface (declare in the idl file, using HRESULT return type
> etc..)
> > but can I put C++ classes in my COM Interface? how to do that? How the
> > member will be accessed from the COM client?



Tue, 21 Sep 2004 18:20:41 GMT  
 C++ classes in a COM Interface?
Yes but my Dll exposes classes and not just functions... the issue is
here...


Quote:
> You can use your dll in C# whitout convert it to COM.
> Look for .NET Interop Services.



> > Maybe I was not clear...
> > If have a dll which is not COM but I need to use this dll into a C#
> > project...
> > So I want to turn this Dll into a COM Server and add it as a reference
in
> my
> > C# project (COM client)...
> > I know that if I create an ATL project with MFC support I can put my
> > exported Dll function into the COM Server Interface and use it in my C#
> > project... of course these functions should be first modified to be COM
> > compliant (use HRESULT as return data types, create a tlb file for .NET
> > etc...) but I'd like to know how I can do the same with classes instead
of
> > simple functions...Is it possible to expose a class within a COM
interface
> > instead of functions...? How this class will be handled in the COM
client?
> > Thanks



> > You cannot pass C++ classes via COM interfaces (if that's what you are
> > asking). You cannot export C functions in COM either (you certainly can
> > export functions from a DLL that serves COM objects, but that us not
> > COM - you are going around it).

> > --
> > =====================================
> > Alexander Nickolov
> > Microsoft MVP [VC], MCSD

> > MVP VC FAQ: http://www.mvps.org/vcfaq
> > =====================================



> > > Is it possible to implement C++ classes into a COM interface?
> > > I want to turn my "simple" DLL into a COM component using ATL wizard
and
> > MFC
> > > support... I understand how it works with exported functions that I
put
> in
> > > the COM Interface (declare in the idl file, using HRESULT return type
> > etc..)
> > > but can I put C++ classes in my COM Interface? how to do that? How the
> > > member will be accessed from the COM client?



Tue, 21 Sep 2004 20:51:27 GMT  
 C++ classes in a COM Interface?
Ok I've looked at the .NET SDK samples and I can directly use my Dll even if
it exports classes.... but My Dll is using MFC within the exported classes,
would it be a big issue when invoking the dll from my C# project?



Quote:
> You can use your dll in C# whitout convert it to COM.
> Look for .NET Interop Services.



> > Maybe I was not clear...
> > If have a dll which is not COM but I need to use this dll into a C#
> > project...
> > So I want to turn this Dll into a COM Server and add it as a reference
in
> my
> > C# project (COM client)...
> > I know that if I create an ATL project with MFC support I can put my
> > exported Dll function into the COM Server Interface and use it in my C#
> > project... of course these functions should be first modified to be COM
> > compliant (use HRESULT as return data types, create a tlb file for .NET
> > etc...) but I'd like to know how I can do the same with classes instead
of
> > simple functions...Is it possible to expose a class within a COM
interface
> > instead of functions...? How this class will be handled in the COM
client?
> > Thanks



> > You cannot pass C++ classes via COM interfaces (if that's what you are
> > asking). You cannot export C functions in COM either (you certainly can
> > export functions from a DLL that serves COM objects, but that us not
> > COM - you are going around it).

> > --
> > =====================================
> > Alexander Nickolov
> > Microsoft MVP [VC], MCSD

> > MVP VC FAQ: http://www.mvps.org/vcfaq
> > =====================================



> > > Is it possible to implement C++ classes into a COM interface?
> > > I want to turn my "simple" DLL into a COM component using ATL wizard
and
> > MFC
> > > support... I understand how it works with exported functions that I
put
> in
> > > the COM Interface (declare in the idl file, using HRESULT return type
> > etc..)
> > > but can I put C++ classes in my COM Interface? how to do that? How the
> > > member will be accessed from the COM client?



Tue, 21 Sep 2004 21:15:00 GMT  
 C++ classes in a COM Interface?

I had a similar situation.  All I did was create a simple
object whose only member was an instance of the class
whose functionality I wanted to export.  I created several
interfaces(in IDL) to expose the various methods of my
original C++ class.  I then had my simple object implement
these interfaces.  The implementation of the various
methods of the simple object where merely calls to my sole
member object's member functions.  Of course I had to do
some data massaging from COM compliant data types(i.e.
BSTR's) but it was pretty straight forward.

Quote:
>-----Original Message-----
>Is it possible to implement C++ classes into a COM
interface?
>I want to turn my "simple" DLL into a COM component using
ATL wizard and MFC
>support... I understand how it works with exported

functions that I put in
Quote:
>the COM Interface (declare in the idl file, using HRESULT
return type etc..)
>but can I put C++ classes in my COM Interface? how to do
that? How the
>member will be accessed from the COM client?

>.



Wed, 22 Sep 2004 04:45:32 GMT  
 C++ classes in a COM Interface?


Quote:
> Yes but my Dll exposes classes and not just functions... the issue is
> here...

Why not just simply wrap an member instance of the C++ object in the COM
class (an ATL template class)? The COM server would be analagous to the C++
class. COM functionality would then be mapped to the C++ member instance.
There might be some type mapping challenges if you have any non-OLE types
being passed among member functions.

You will end up with a dependency from your COM library to your C++ library.

Not pretty but it might work for you.

Quote:


> > You can use your dll in C# whitout convert it to COM.
> > Look for .NET Interop Services.



> > > Maybe I was not clear...
> > > If have a dll which is not COM but I need to use this dll into a C#
> > > project...
> > > So I want to turn this Dll into a COM Server and add it as a reference
> in
> > my
> > > C# project (COM client)...
> > > I know that if I create an ATL project with MFC support I can put my
> > > exported Dll function into the COM Server Interface and use it in my
C#
> > > project... of course these functions should be first modified to be
COM
> > > compliant (use HRESULT as return data types, create a tlb file for
.NET
> > > etc...) but I'd like to know how I can do the same with classes
instead
> of
> > > simple functions...Is it possible to expose a class within a COM
> interface
> > > instead of functions...? How this class will be handled in the COM
> client?
> > > Thanks



> > > You cannot pass C++ classes via COM interfaces (if that's what you are
> > > asking). You cannot export C functions in COM either (you certainly
can
> > > export functions from a DLL that serves COM objects, but that us not
> > > COM - you are going around it).

> > > --
> > > =====================================
> > > Alexander Nickolov
> > > Microsoft MVP [VC], MCSD

> > > MVP VC FAQ: http://www.mvps.org/vcfaq
> > > =====================================



> > > > Is it possible to implement C++ classes into a COM interface?
> > > > I want to turn my "simple" DLL into a COM component using ATL wizard
> and
> > > MFC
> > > > support... I understand how it works with exported functions that I
> put
> > in
> > > > the COM Interface (declare in the idl file, using HRESULT return
type
> > > etc..)
> > > > but can I put C++ classes in my COM Interface? how to do that? How
the
> > > > member will be accessed from the COM client?



Mon, 27 Sep 2004 03:28:45 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Howto Expose a normal C++ class with methods via an Interface Class in ATL COM

2. existing c++ class to COM interface

3. ATL COM - Passing ATL COM classes through another ATL COM class in the same app

4. using non dll-interface class as base for dll-interface class

5. Contract between COM class and set of interfaces?

6. ATL COM Interface not displayed in Class View

7. ATL COM Interface not displayed in Class View

8. Slow ClassView Editing of COM Interfaces on Nested Classes

9. Creating a COM interface to a CWinApp derived class

10. Exposing COM interface in managed C++

11. Passing byte array from C# to C++ COM interface

12. Passing byte array from C# to C++ COM interface

 

 
Powered by phpBB® Forum Software