6

Is it possible to create an instance of a COM object with just the dll and no regsvr32?

My main goal here is to create an instance of a directshow filter and insert it into my graph-but I don't want to us regsvr32 to register the filter. The filter will be in a dll/ax that will be distributed with my application and will be present in my path. I will know the CLSID as well.

So basically all I need is a way to create an instance of the type while just having the dll/ax and the CLSID. Is this possible in C#?

Duane
  • 570
  • 4
  • 14

3 Answers3

7

Sounds like you want to use registration-free COM.

Logan Capaldo
  • 39,555
  • 5
  • 63
  • 78
  • 2
    FYI: No, you can't use fusion for this as directx filters need more reg keys to register correctly in filter graph than fusion can provide for. – wqw Dec 27 '10 at 23:05
  • @wqw If this is the case you probably want to add this as answer, as none of the approaches for using a COM component without registering it are going to work for this case. – Logan Capaldo Dec 27 '10 at 23:48
  • @wqw: You might be able to use RegOverridePredefKey for that stuff, though. ( http://msdn.microsoft.com/en-us/library/ms724901%28VS.85%29.aspx ) – Leo Davidson Dec 28 '10 at 00:09
  • Unfortunately this looks like the correct answer. At least I can give it a try now. If it works for directshow I'll report the details here. – Duane Dec 29 '10 at 13:55
  • @wqw That's not correct. It's entirely possible to just "new" up filters and stick them in a graph. Registry is only necessary for intelligent connect and the like. – Rytmis Feb 06 '13 at 11:39
3

It's possible, LoadLibrary() and GetProcAddress to the get the DllGetClassObject() entrypoint. You are bypassing a bunch of COM plumbing code that was designed to make you fall into the pit of success. Especially the stuff that takes care of the ThreadingModel. Or the tricks you can use to make 32-bit code run in a 64-bit process, tends to be important with video.

Using reg-free COM with a manifest can make you fall back into that pit.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

When you create a COM instance, Windows looks in the registry, finds out what dll to load, how to load it, and then loads the dll and finds the class you were looking for. If you want to skip this lookup algorithm, then you have to implement it, and I don't think it's easy. But certainly doable.

UPDATE: look for the CoLoadLibrary function, maybe it's not that hard after all. I think that COM servers call CoRegisterClassObject when they are loaded, that's how Windows find them, and you can call CoGetClassObject. I'm still in the dark, though, so go ahead and read MSDN.

fejesjoco
  • 11,763
  • 3
  • 35
  • 65