3

I'm looking at implementing custom COM activation logic for a managed class library, in MkParseDisplayName/BindToObject manner.

This way, creating an object from VB might look like this:

obj = GetObject("clsid:12341234-1234-1234-1234-123412341234:!UniqueObjectId")

That would not be a problem for an out-of-proc server (using CoRegisterClassObject). However, for an in-proc server, I'd need to alter the implementation of DllGetClassObject, which is normally provided by mscoree.dll. Is this possible at all?

The only other option I see is to create a C# singleton object to serve as class factory and implement IParseDisplayName on it. In theory, such singleton could also register a custom IClassFactory class object with CoRegisterClassObject(CLSCTX_INPROC_SERVER), but the singleton itself would need to get instantiated first, anyway.

noseratio
  • 59,932
  • 34
  • 208
  • 486
  • Do you want to be able to create different objects given a specific string, or just pass arguments to a newly created object? In the latter case, you can just declare & implement IParseDisplayName on the .NET class that's behind the 12341234-1234-1234-1234-123412341234 guid. – Simon Mourier Oct 11 '13 at 12:11
  • @SimonMourier, the original COM DLL (which is a candidate for rewrite in C#) has a class factory that implements `IParseDisplayName` (exactly as described [here](http://www.microsoft.com/library/images/msdn/library/periodic/periodic/msj/axcom797.htm)), and then creates different objects, depending on the trailing item of the moniker. Ideally, I'd like to keep that behavior. – noseratio Oct 11 '13 at 12:45
  • You could mangle the default .NET registry setup to point to a specific DLL, not mscoree – Simon Mourier Oct 11 '13 at 13:32
  • I thought about it, but i don't know how to export `DllGetClassObject` from a managed C# DLL, not sure if that's possible. – noseratio Oct 11 '13 at 13:41
  • 2
    Yes, it's possible but kinda hacky (but you're in hack world already :-): http://stackoverflow.com/questions/4818850/is-is-possible-to-export-functions-from-a-c-sharp-dll-like-in-vs-c – Simon Mourier Oct 11 '13 at 13:43
  • ildasm is an interesting, albeit a bit too extreme option, thanks :-) – noseratio Oct 11 '13 at 13:48

0 Answers0