1

I have a VB6 COM DLL. I want to use it from C++. I know how to register it, generate a tlb file from the DLL, and #import it in C++.

I'd like however, to load and use DLLs like this dynamically, at runtime, without knowing them in advance. Is this possible?

Thanks,

  • Do you want to avoid registering them, or avoid generating the type library and #importing? Or both (which I'm not sure is possible)? – MarkJ Jun 04 '10 at 12:02

3 Answers3

4

Yes, but you need to get the question clearer.

Sometimes, you do know the COM interface upfront, just not the implementation. In that case, you can create a dummy implementation of the interface and #import that. At runtime, you'd still register the real component, get an object from it (via CoCreateInstance probably) and store that in an appropriate smart pointer.

With VB6, it's a bit less direct. This adds a level of indirection. Read up on IDispatch. You need to get that known interface to describe an unknown interface. That way, the unknown interface can be obtained at runtime.

MSalters
  • 173,980
  • 10
  • 155
  • 350
2

IMHO, You need at least some common interface (so you known what to call in the C++ side).

I'd do something like:

  1. Define a common interface (in its own DLL/TLB)

  2. Implement this interface in one or more COM servers

  3. Import this interface in the C++ side (let's call it client)

  4. Define a way to pass the progid of the COM server you want to work with (load dynamically) in the client.

Hope this helps

Vagaus
  • 4,174
  • 20
  • 31
1

Take a look at these two MSDN articles about Registration-Free Activation of COM Components:

There also have been some similar question here on StackOverflow:

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Frank Bollack
  • 24,478
  • 5
  • 49
  • 58