Вопрос

I created a C# COM accessible dll that I want to consume in VB6 I was able to consume in VB6 my COM object with a hard reference to the TLB. What I am trying to do now is to remove this reference and load it dynamically I am creating it as follows:

Dim keylok As Object
Set keylok = CreateObject("MyClassLib.MyObject")

I get the Run-time error 424 "Object Required" once I hit the second line. But when I create it as follows:

Dim keylok As MyObject
Set keylok = CreateObject("MyClassLib.MyObject")

It works fine. I am not sure why would that make a difference. Anyway I cannot use the second one because I would still need to have the physical reference.

I tried also as a sort of debugging to write to file in my COM object constructor to if it really gets called. And yes it does, I'm even able to call other methods in my COM object sucessfully inside the constructor.

I was even able to load dynamically and consume it from another C# app using:

dynamic myObj = Activator.CreateInstance(Type.GetTypeFromProgID("MyClassLib.MyObject"));

Did any one encounter something like that before?

Это было полезно?

Решение

I found the solution with the help of @rskar input. So, I thought I'm gonna answer my question, in case any one faces the same problem.

My object didn't impelement IDsipatch. So all I had to do it to decorate my C# COM interface with InterfaceType(ComInterfaceType.InterfaceIsDual) So it implements both IUnknown and IDispatch. Originally it was decorated with InterfaceType(ComInterfaceType.InterfaceIsIUnknown)

Другие советы

I think you are going to require the .tlb anyway. COM objects need to be capable of being marshalled as the .Net hosting runs on a different thread to the VB6 runtime. The default marshalling uses information from the typelibrary to do this. IDIspatch has 4 methods and 2 of these are to do with accessing type information. So possibly if you removed the .tlb, when you create the IDispatch COM attempts to call up the ITypeInfo from this and dies failing to load the registered typelibrary. If you eliminate the .tlb you will become unable to be marshalled and likely you would have to provide a custom marshaller for your interface.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top