Discussion:
Make a VB.net class inherit from a COM Inteface
(too old to reply)
Thorsten Tarrach
2009-09-10 08:33:54 UTC
Permalink
Hi,

I'm trying to implement an extension to Live Photo Gallery as specified here
in managed code:
http://msdn.microsoft.com/en-us/library/cc967061.aspx

It outlines a simple three step guide for managed applications to implement
this interface, but this does not work at all for me. I tried both with a
Windows Froms Form or with a WPF Window. I activated AllowDrop, handled the
relevant events and registered the classes with regasm /codebase /tbl. It
is also clear why it does not work: When I register this assembly and look
at the resulting registration using OLE-COM Object Viewer the registered
class only inherits from IDispatch, but not from IDropTarget.

So I tried to implement a COM Class manually in VB.net, inheriting from an
IDropTarget interface that is defined like this one:
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.ole.interop.idroptarget.aspx
but again after registration my class does not inherit the interface
IDropTarget.

Is it possible to make a .net class inherit from a COM interface in such a
way that this inheritance is also visible to COM?

In any case the three steps to write a managed extension to Live Photo
Gallery either don't work or are not detailed enough for me to successfully
reproduce.

Can you either point out where I went wrong with these three steps or with
manually creating a COM class?

Thanks,
Thorsten
Jialiang Ge [MSFT]
2009-09-10 12:50:15 UTC
Permalink
Hello Thorsten

Did you mark the interface as public and ComVisible?

For example

[Guid("32DBA9B0-BE1F-357D-827F-0196229FA0E2")] // IID
[ComVisible(true)]
// The public interface describing the COM interface of the coclass
public interface ICSSimpleObject2
{
...
}

[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[Guid("4B65FE47-2F9D-37B8-B3CB-5BE4A7BC0926")] // CLSID
[ProgId("CSCOMServerDll.CustomCSSimpleObject2")] // ProgID
public class CSSimpleObject2 : ICSSimpleObject2
{
...
}

If you want a working example, please refer to the CSDllCOMServer sample in
All-In-One Code Framework (http://cfx.codeplex.com). CSSimpleObject2.cs
demonstrates how to explicitly set interfaces for a COM class.

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
***@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
Thorsten Tarrach
2009-09-11 07:30:10 UTC
Permalink
Hi Jialiang,

I tried again, this time implementing the
Microsoft.VisualStudio.OLE.Interop.IDropTarget interface. But each time I
export the type library my class does not inherit the COM interface
IDropTarget. I'm not sure it can be done in managed code to inherit a COM
interface.
I'm now switching to ATL hoping to have more luck with that.

Thanks,
Thorsten
Post by Jialiang Ge [MSFT]
Hello Thorsten
Did you mark the interface as public and ComVisible?
For example
[Guid("32DBA9B0-BE1F-357D-827F-0196229FA0E2")] // IID
[ComVisible(true)]
// The public interface describing the COM interface of the coclass
public interface ICSSimpleObject2
{
...
}
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[Guid("4B65FE47-2F9D-37B8-B3CB-5BE4A7BC0926")] // CLSID
[ProgId("CSCOMServerDll.CustomCSSimpleObject2")] // ProgID
public class CSSimpleObject2 : ICSSimpleObject2
{
...
}
If you want a working example, please refer to the CSDllCOMServer sample in
All-In-One Code Framework (http://cfx.codeplex.com). CSSimpleObject2.cs
demonstrates how to explicitly set interfaces for a COM class.
Regards,
Jialiang Ge
Microsoft Online Community Support
=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
Giovanni Dicanio
2009-09-11 08:39:20 UTC
Permalink
Post by Thorsten Tarrach
I tried again, this time implementing the
Microsoft.VisualStudio.OLE.Interop.IDropTarget interface. But each time I
export the type library my class does not inherit the COM interface
IDropTarget. I'm not sure it can be done in managed code to inherit a COM
interface.
I'm now switching to ATL hoping to have more luck with that.
I'm not sure of what you are going to achieve, but if you are going to
write a kind of shell extension, then I would suggest you to just use
C++ and ATL.

There is a blog post that states it clearly:

"Do not write in-process shell extensions in managed code"
http://blogs.msdn.com/oldnewthing/archive/2006/12/18/1317290.aspx

What you might try to do is to write a "skeleton" shell extension in C++
with ATL, and from that spwan a *new process* that is written in .NET
(in this case the CLR is not injected in processes that use the shell
namespace).

Giovanni
Thorsten Tarrach
2009-09-11 12:35:33 UTC
Permalink
Well, as stated in the original post, I'm just trying to extend the Live
Photo Gallery. So that should not cause any problems.
Post by Giovanni Dicanio
Post by Thorsten Tarrach
I tried again, this time implementing the
Microsoft.VisualStudio.OLE.Interop.IDropTarget interface. But each time I
export the type library my class does not inherit the COM interface
IDropTarget. I'm not sure it can be done in managed code to inherit a COM
interface.
I'm now switching to ATL hoping to have more luck with that.
I'm not sure of what you are going to achieve, but if you are going to
write a kind of shell extension, then I would suggest you to just use C++
and ATL.
"Do not write in-process shell extensions in managed code"
http://blogs.msdn.com/oldnewthing/archive/2006/12/18/1317290.aspx
What you might try to do is to write a "skeleton" shell extension in C++
with ATL, and from that spwan a *new process* that is written in .NET (in
this case the CLR is not injected in processes that use the shell
namespace).
Giovanni
Giovanni Dicanio
2009-09-11 13:19:47 UTC
Permalink
Post by Thorsten Tarrach
Well, as stated in the original post, I'm just trying to extend the Live
Photo Gallery. So that should not cause any problems.
I've never done something like that, but if Live Photo Gallery extension
is done via COM (in a way similar to shell extensions), you may have
troubles if you inject CLR (required by your .NET extension) in Live
Photo Gallery process...

Giovanni
Thorsten Tarrach
2009-09-14 14:01:14 UTC
Permalink
Yes, I wrote it in ATL now. But as a suggestion for MS: Please update the
documentation in MSDN and remove the idea that this can be done in managed
code and instead make a sample plugin available that passes the filelist on
as a command line argument to some other application.

Thorsten
Post by Giovanni Dicanio
Post by Thorsten Tarrach
Well, as stated in the original post, I'm just trying to extend the Live
Photo Gallery. So that should not cause any problems.
I've never done something like that, but if Live Photo Gallery extension
is done via COM (in a way similar to shell extensions), you may have
troubles if you inject CLR (required by your .NET extension) in Live Photo
Gallery process...
Giovanni
Jialiang Ge [MSFT]
2009-09-18 09:30:51 UTC
Permalink
Hello Thorsten

Thanks for the suggestion. Please give me some time. I'm discussing the
issue with the product group. I will get back to you soon.

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
***@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
Jialiang Ge [MSFT]
2009-09-22 10:56:29 UTC
Permalink
Hello Thorsten

The generated interop assembly imports the interfaces like IDropTarget
using the [ComImport] attribute. Tlbexp ignores these "imported" interfaces
when it generates tlb from your assembly - the interfaces are supposed to
come from another TLB, and thus exporting them would mean duplicated
definitions. That's why you did not see IDropTarget in the tlb, though your
COM class already implements the interface.

If you want to force the export of the interfaces, copying the source code
of the interop assemblies into your project (you can view the source code
using .net reflector), and then dropping the [ComImport] attribute on all
those interfaces.

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
***@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Loading...