C++/CLI Interfaces

G

Guest

Two questions:

1) I have an assembly that defines the interface for a component. The
assembly only contains the interface (as per component development guidance),
a different assembly contains the C++ classes that implement the interface.
When I write a VB app that references both strong named assemblies, the
VS2005 object browser and intellisense tells me the namespace (shared by both
interface and implementation class) identifier is ambiguous because the
interface is showing up in both assemblies. What am I doing wrong?

2) I have a few static events on an C++ implementation class found in a
strong named assembly. All works fine when a simple VB app references the
assembly, the VB app can register for and receive the events but has to
reference the C++ class in the assembly. If I try to add the events to the
interface the C++ class implements, I get compile errors that indicate you
cannot have static events on an interface. If I get rid of the static
modifier, all heck breaks loose. Any suggestions (note the events pass
arguments)?

Thanks
 
T

Tamas Demjen

NEW2.NET said:
1) I have an assembly that defines the interface for a component. The
assembly only contains the interface (as per component development guidance),
a different assembly contains the C++ classes that implement the interface.
When I write a VB app that references both strong named assemblies, the
VS2005 object browser and intellisense tells me the namespace (shared by both
interface and implementation class) identifier is ambiguous because the
interface is showing up in both assemblies. What am I doing wrong?

Are you sure the C++ implementation is referencing the assembly instead
of including it? You have to reference it with #using, not copy-pasting
it with #include. If you use #include, it will certainly be a completely
separate class with the same name, thus causing duplicate identifiers.

I can't comment on #2, never done that before.

Tom
 
B

Ben Voigt

2) I have a few static events on an C++ implementation class found in a
strong named assembly. All works fine when a simple VB app references the
assembly, the VB app can register for and receive the events but has to
reference the C++ class in the assembly. If I try to add the events to
the
interface the C++ class implements, I get compile errors that indicate you
cannot have static events on an interface. If I get rid of the static
modifier, all heck breaks loose. Any suggestions (note the events pass
arguments)?

While an interface can have static members in .Net, they aren't in any way
connected to classes implementing that interface. Interfaces define a
contract on objects (instances) that implement the interface, not on
classes.
 

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