Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: COM DLL
In the following code, why do the methods Register and Unregister require a type parameter?
using System.Runtime.InteropServices;
 
namespace Foo {
    [Guid("...")]
    [ComVisible(true)]
    public class Bar {
        [ComRegisterFunction]
        private static void Register  (Type type) { ... }
 
        [ComUnregisterFunction]
        private static void Unregister(Type type) { ... }
    }
}
I thought that perhaps it was because you only need one such function per assembly to register all of the types in that assembly, but that is not the case. No matter what I try (a class inheriting from Bar that is COM exportable, a subclass of Bar that is COM exportable, other unrelated classes that are COM exportable), the methods are only ever called once with (type == typeof(Bar)). I doubt the designers would require a useless parameter, so my question is, why is the type parameter required on these methods? Am I missing a case where the type parameter could differ from the class containing the method? Thanks,
Posted 1-Feb-12 16:19pm
Skippums2.2K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are missing the case where the type parameter differs from the class containing the method.
 
using System.Runtime.InteropServices;
 
namespace Test {
 
    [ComVisible(true)]
    public abstract class A {
        public static void Register(Type type) {
 
        }
 
        public static void Unregister(Type type) {
 
        }
    }
 
    [ComVisible(true)]
    public class B : A {
 
    }
}
 
When registerring, the following method will be called:
 
B.Register(typeof(B))
 
Since the Register method is part of the class A, the call will be translated to
 
A.Register(typeof(B))
 
You may get problems when using typeof(class) instead of type argument.
 
Hope this help to someone.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 10 Feb 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100