Interface from C# to VB 6 not working

D

Doug

I am working on an existing .NET (C Sharp) component that had a com
interface that was used by a VB component. When it was originally
written, it had the SSEAssemblyCom class below - minus the two last
methods (for space I modified method names in my example below). I
added those. Everything but the two new methods I added referenced
the ISSEAssemblyCom interface below.

I was told I would need to create a secondary interface
(ISSEAssemblyCom2 below) that SSEAssemblyCom would use which I've done
as you can see in the code below. I created a tlb file for my .NET
component to use by my VB component and reference it and now my VB
component is only recognizing the two new methods I wrote and not any
of the other ones. I checked with a developer in my company and he
had me try putting the methods from ISSEAssemblyCom into
ISSEAssemblyCom2 and try it again. I did that and now my VB component
recognizes the first 12 but not the 2 new ones I added...??? Does
anyone know how this is supposed to be done properly so that I can
reference both the old and new interface methods? (By the way, I took
out the code below in each method of SSEAssemblyCom as I figured you'd
only care about the signatures anyways)

[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
[Guid("A GUID VALUE HERE")]
[ProgId("PLXX0005.SSEAssemblyCom")]
public class SSEAssemblyCom : ISSEAssemblyCom, ISSEAssemblyCom2
{
public void Method1(string sz)
public void Method2(string sz)
public bool Method3(string sz, string sz2, out string sz3, int i)
public bool Method4(string sz, out string sz2, int i)
public void Method5(string sz)
public void Method6(string sz)
public string Method7(string sz)
public bool Method8(string sz, out string sz2, int i)
public void Method9(string sz, string sz2)
public bool Method10(string sz, out string sz2, int i)
public bool Method11(string sz)
public void Method12(string sz, string sz2)
public void MyNewMethod1(string sz, out string sz2)
public bool MyNewMethod2(string sz, out string sz2)
}

[ComVisible(true)]
[Guid("ANOTHER GUID VALUE HERE")]
public interface ISSEAssemblyCom
{
[DispId(1)] void Method1(string sz)
[DispId(2)] void Method2(string sz)
[DispId(3)] bool Method3(string sz, string sz2, out string sz3,
int i)
[DispId(4)] bool Method4(string sz, out string sz2, int i)
[DispId(5)] void Method5(string sz)
[DispId(6)] void Method6(string sz)
[DispId(7)] string Method7(string sz)
[DispId(8)] bool Method8(string sz, out string sz2, int i)
[DispId(9)] void Method9(string sz, string sz2)
[DispId(10)] bool Method10(string sz, out string sz2, int i)
[DispId(11)] bool Method11(string sz)
[DispId(12)] void Method12(string sz, string sz2)
}

[ComVisible(true)]
[Guid("A THIRD GUID VALUE HERE")]
public interface ISSEAssemblyCom2 : ISSEAssemblyCom
{
[DispId(13)] void MyNewMethod1(string sz, out string sz2)
[DispId(14)] bool MyNewMethod2(string sz, out string sz2)
}
 
C

Chris Jackson

Try marking the interface you want to consume with the attribute:

[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]


--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

Doug said:
I am working on an existing .NET (C Sharp) component that had a com
interface that was used by a VB component. When it was originally
written, it had the SSEAssemblyCom class below - minus the two last
methods (for space I modified method names in my example below). I
added those. Everything but the two new methods I added referenced
the ISSEAssemblyCom interface below.

I was told I would need to create a secondary interface
(ISSEAssemblyCom2 below) that SSEAssemblyCom would use which I've done
as you can see in the code below. I created a tlb file for my .NET
component to use by my VB component and reference it and now my VB
component is only recognizing the two new methods I wrote and not any
of the other ones. I checked with a developer in my company and he
had me try putting the methods from ISSEAssemblyCom into
ISSEAssemblyCom2 and try it again. I did that and now my VB component
recognizes the first 12 but not the 2 new ones I added...??? Does
anyone know how this is supposed to be done properly so that I can
reference both the old and new interface methods? (By the way, I took
out the code below in each method of SSEAssemblyCom as I figured you'd
only care about the signatures anyways)

[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
[Guid("A GUID VALUE HERE")]
[ProgId("PLXX0005.SSEAssemblyCom")]
public class SSEAssemblyCom : ISSEAssemblyCom, ISSEAssemblyCom2
{
public void Method1(string sz)
public void Method2(string sz)
public bool Method3(string sz, string sz2, out string sz3, int i)
public bool Method4(string sz, out string sz2, int i)
public void Method5(string sz)
public void Method6(string sz)
public string Method7(string sz)
public bool Method8(string sz, out string sz2, int i)
public void Method9(string sz, string sz2)
public bool Method10(string sz, out string sz2, int i)
public bool Method11(string sz)
public void Method12(string sz, string sz2)
public void MyNewMethod1(string sz, out string sz2)
public bool MyNewMethod2(string sz, out string sz2)
}

[ComVisible(true)]
[Guid("ANOTHER GUID VALUE HERE")]
public interface ISSEAssemblyCom
{
[DispId(1)] void Method1(string sz)
[DispId(2)] void Method2(string sz)
[DispId(3)] bool Method3(string sz, string sz2, out string sz3,
int i)
[DispId(4)] bool Method4(string sz, out string sz2, int i)
[DispId(5)] void Method5(string sz)
[DispId(6)] void Method6(string sz)
[DispId(7)] string Method7(string sz)
[DispId(8)] bool Method8(string sz, out string sz2, int i)
[DispId(9)] void Method9(string sz, string sz2)
[DispId(10)] bool Method10(string sz, out string sz2, int i)
[DispId(11)] bool Method11(string sz)
[DispId(12)] void Method12(string sz, string sz2)
}

[ComVisible(true)]
[Guid("A THIRD GUID VALUE HERE")]
public interface ISSEAssemblyCom2 : ISSEAssemblyCom
{
[DispId(13)] void MyNewMethod1(string sz, out string sz2)
[DispId(14)] bool MyNewMethod2(string sz, out string sz2)
}
 
D

Doug

Hi Chris,
That didn't work either. I got the same results as before even
with adding that attribute.

I tried creating a brand new class (SSEAssemblyCom2) that
inherited from the new interface (ISSEAssemblyCom2), and I could see
the first 12 methods in the intellisense in VB when I use
SSEAssemblyCom and the last two methods where I use SSEAssemblyCom2,
however actually creating the object in VB failed for SSEAssemblyCom2
so I'm at a complete loss at what to do here.
 
D

Doug

Just a quick update. I have attempted the following to get around
this problem and nothing works. If anyone has any ideas as to how I
can get two new methods from C# to be called through VB in an
interface I would love to hear it...:)

1) Tried with just the old interface with 12 methods and got rid of
my two new ones - this worked just fine but since I need the new
ones...:)

2) Added two new methods to old interface - old methods worked, new
ones caused "Object doesn't support this property or method" error.

3) Left old interface with two new methods - changed the guid -
caused "Type Mismatch" error when object was being created.

4) Created new interface with two new methods, had my class inherit
from both the old and new interface - VB does not show the new methods
in intellisense and trying to call them causes "Object doesn't support
this property or method" error (interestingly enough if I change my
class to inherit from the new class first and the old class second,
then the old methods don't show up in intellisense, the new ones do).

5) In new interface, had it inherit from old interface and had my
class inherit just from new interface - VB does not show the old
methods in intellisense and trying to call them causes "Object doesn't
support this property or method" error.

6) In old interface, had it inherit from new interface - VB does not
show the new methods in intellisense and trying to call them causes
"Object doesn't support this property or method" error.

7) In new interface, removed inheritance from old interface - put
methods from old interface in new interface, had class inherit from
new interface only. VB shows all methods in intellisense, but throws
"Object doesn't support this property or method" error when calling
old methods. New method calls work just fine.

8) Kept new and old interface, had class inherit from old interface.
Created brand new class and had it inherit from new interface. Create
a seperate object in VB to call new methods that would use new class
from C# code. When object attempted to get created got the error:
"Could not load type PLXX0005.SSEAssemblyCom2 from assembly PLXX0005.
PLXX0005.SSEAssemblyCom2"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top