Reputation: 12475
I have a vb6 interface called CLSFW_SBSession
Public Property Let CommandLine(ByVal RHS As String)
End Property
Public Property Get ProcessToken() As String
End Property
I have a c# interface that needs to extend the vb6 interface.
[ComVisible(true)]
[Guid("8d7c2025-221d-400f-b81c-2f78d65c5842")]
public interface IClsSbSession : CLSFW_SBSession
{
string ProcessToken2 { get; }
string CommandLine2 { get; set; }
}
I can't reference the ddl com interface from c# because the dll c# references the dll com.
Is possible do it dynamically?
Upvotes: 2
Views: 159
Reputation: 941873
VB6 does not support interfaces, CLSFW_SBSession is actually a coclass name. It still auto-generates an interface, required to make COM work. It has the same name as the class, but with an underscore prefix. Another nasty little detail is that .NET does not support multiple inheritance. Which requires you to re-implement the base interface methods. A rather major flaw in .NET COM interop is that you also have to redeclare the base interface methods. So it needs to be:
[ComVisible(true)]
[Guid("8d7c2025-221d-400f-b81c-2f78d65c5842")]
public interface IClsSbSession : _CLSFW_SBSession
{
// These are guesses:
string CommandLine { get; set}
string ProcessToken { get; }
// End of guessing
string ProcessToken2 { get; }
string CommandLine2 { get; set; }
}
It is critical that the declarations marked as guesses in the snippet are an exact match with the members of the _CLSFW_SBSession interface. VB6 makes this hard to find out, you must run OleView.exe from the command prompt and use File + View Typelib to look at the type library.
Adding a reference to the VB6 generated type library cannot be a problem. Use Tlbimp.exe if necessary.
Fwiw, you should strongly avoid doing this, ought to be clear that this is pretty brittle. It is not clear why you want to do it this way, do consider taking advantage of COM's ability to have a coclass implement multiple interfaces. The only hangup with that is that VB6 and scripting languages only support the default interface so your .NET class won't be easily usable from such an app. Consider encapsulation instead, you can add a factory method that returns _CLSFW_SBSession.
Upvotes: 1