COM problems

  • Thread starter Thread starter Michal
  • Start date Start date
M

Michal

Hi.

I've sent this message earlier, but maybe it wasn't noticed :) I didn't find
solution of my
problem :( I hope someone can help me here... I promise, I won't post it
again :)

The problem is:

Im writing a library in C# (COM Library). This library will be used by an
application, which is wrote in VB6. I will call it "MainApp".

In my library I'm reading property from object which is shared from MainApp.

My class looks like:

[Guid("6FA89BBA-A87F-4e0a-8A0D-9B2FA0C7BD53"),
ClassInterface(ClassInterfaceType.None)]

public class MainClass : MainApp.ExternalClass
{
void InitClass(MainApp.Interface myIntrf)
{
MainApp.SomeObj s = myIntrf.MyProperty;
}
}

MainApp.ExternalClass - abstract class (I'm implementing its methods).

When I'm buliding the project, VS says:
"Property, indexer, or event 'MyProperty' is not supported by the language;
try directly calling accessor methods 'MainApp.get_MyProperty()' or
'MainApp.set_MyProperty(ref MainApp.SomeObj)''".

So i changed my code and I'm invoking get_MyPropert() method. Buuuut, when I
want to access some fields in MainApp.SomeObj an exception is thrown:
"System.InvalidCastException: QueryInterface for interface
'MainApp._SomeObj' failed."

What should I do, so my returing (from accessor method) object
('MainApp._SomeObj') is valid ??

I'll be appreciative for any advise...

Michal
 
Michal,

This really isn't my area of expertise, but hopefully this will either give
you some direction, or convince one of the posters who know alot more about
this subject than me to respond!

When you define the attribute ClassInterface(ClassInterfaceType.None), I
think you have to define an interface yourself, and refer to this interface
in the class definition. For test purposes, you could initially try setting
ClassInterfaceType.AutoDual which will add the interfaces for early and late
binding for you automatically.

Be aware though that the AutoDual and AutoDispatch settings create
versioning problems, and so I recommend that you use ClassInterfaceType.None
as you currently are.

Hope this helps,
Chris.
 
Maybe Your're right, but unfortunately the external application (MainApp)
wasn't written by me, so I can't add any interface.

I'll try to figure it out... somehow :) Thanks anyway for your adwise :)

Michal


Chris Ballard said:
Michal,

This really isn't my area of expertise, but hopefully this will either give
you some direction, or convince one of the posters who know alot more about
this subject than me to respond!

When you define the attribute ClassInterface(ClassInterfaceType.None), I
think you have to define an interface yourself, and refer to this interface
in the class definition. For test purposes, you could initially try setting
ClassInterfaceType.AutoDual which will add the interfaces for early and late
binding for you automatically.

Be aware though that the AutoDual and AutoDispatch settings create
versioning problems, and so I recommend that you use ClassInterfaceType.None
as you currently are.

Hope this helps,
Chris.

Michal said:
Hi.

I've sent this message earlier, but maybe it wasn't noticed :) I didn't find
solution of my
problem :( I hope someone can help me here... I promise, I won't post it
again :)

The problem is:

Im writing a library in C# (COM Library). This library will be used by an
application, which is wrote in VB6. I will call it "MainApp".

In my library I'm reading property from object which is shared from MainApp.

My class looks like:

[Guid("6FA89BBA-A87F-4e0a-8A0D-9B2FA0C7BD53"),
ClassInterface(ClassInterfaceType.None)]

public class MainClass : MainApp.ExternalClass
{
void InitClass(MainApp.Interface myIntrf)
{
MainApp.SomeObj s = myIntrf.MyProperty;
}
}

MainApp.ExternalClass - abstract class (I'm implementing its methods).

When I'm buliding the project, VS says:
"Property, indexer, or event 'MyProperty' is not supported by the language;
try directly calling accessor methods 'MainApp.get_MyProperty()' or
'MainApp.set_MyProperty(ref MainApp.SomeObj)''".

So i changed my code and I'm invoking get_MyPropert() method. Buuuut, when I
want to access some fields in MainApp.SomeObj an exception is thrown:
"System.InvalidCastException: QueryInterface for interface
'MainApp._SomeObj' failed."

What should I do, so my returing (from accessor method) object
('MainApp._SomeObj') is valid ??

I'll be appreciative for any advise...

Michal
 
Back
Top