Author Topic: C# and Com Interop  (Read 9826 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Guest
C# and Com Interop
« on: September 09, 2005, 09:15:32 AM »
I have written a small xml config class to manipulate xml files similar to the old ini file usage.

I decided to try and expose this thru com interop so I could use it in some old vb or unmanaged c++ apps if needed.

After doing the following:
1. created a strong name using the sn utility.
2. added a Guid attribute to the public class
3. Changed the compile for com interop to 'true' in the visual studio configuration dialog

I'm able to add the class as a reference and use in a vb project correctly but - I can't see any of the methods or properties in intellisense or the object browser in vb. Almost like late binding is occuring or something.

Did I forget to do something?

Glenn R

  • Guest
Re: C# and Com Interop
« Reply #1 on: September 09, 2005, 10:04:56 PM »
Just had a quick look thru a book I have here and all public types and type members will be visible to COM.

You can control this even further with the [ComVisible(false)] attribute.

Cheers,
Glenn.

Draftek

  • Guest
Re: C# and Com Interop
« Reply #2 on: September 12, 2005, 08:12:11 AM »
Thanks Glenn, I read that too, and all the methods work, I just can't see them in the IDE.

Odd.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: C# and Com Interop
« Reply #3 on: September 12, 2005, 05:37:04 PM »
This is only a guess but your assembly holds all your information about your application and I think your exported function names should appear in there so the clr can make them available/visible to other apps or COM (similar to a dll's exports). Do you have any export type attributes for all of your public functions?
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Glenn R

  • Guest
Re: C# and Com Interop
« Reply #4 on: September 13, 2005, 07:50:54 AM »

Glenn R

  • Guest
Re: C# and Com Interop
« Reply #5 on: September 13, 2005, 07:55:20 AM »
BTW Mick, in this case, the assembly does NOT hold all the info as it's for COM...it needs the .tlb registered as such...and a few more things as well.
COM is not for the faint hearted...glad it's dying and getting a LOT easier with .net, however there are still a few...steps shall we say...to go through.

Hope this helps.

Cheers,
Glenn.

Draftek

  • Guest
Re: C# and Com Interop
« Reply #6 on: September 13, 2005, 07:58:38 AM »
oh geesh!, is that all I have to do. :wink:

Time to create an interface, I guess.

Thanks, I think that will take care of it.

I'll let you know.

Glenn R

  • Guest
Re: C# and Com Interop
« Reply #7 on: September 13, 2005, 08:15:35 AM »
Forgot to mention, that if you can get your hands on the course material for last years AU, there are some examples of doing just this.

The course codes you're after are the CPxxxxx ones.

Cheers,
Glenn.

Draftek

  • Guest
Re: C# and Com Interop
« Reply #8 on: September 13, 2005, 08:22:53 AM »
Worked Perfectly!

Just have to remember to use the interface in vb..

Thanks.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: C# and Com Interop
« Reply #9 on: September 13, 2005, 06:41:08 PM »
BTW Mick, in this case, the assembly does NOT hold all the info as it's for COM...it needs the .tlb registered as such...and a few more things as well.
COM is not for the faint hearted...glad it's dying and getting a LOT easier with .net, however there are still a few...steps shall we say...to go through.

Hope this helps.

Cheers,
Glenn.

Thanks Glenn for the clarification and that link, I wasn't really sure and I forgot all about interfaces :( doh! I knew you had to expose it somewhere though :)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Glenn R

  • Guest
Re: C# and Com Interop
« Reply #10 on: September 14, 2005, 06:58:21 AM »
Draftek,

Everything in COM is an interface and I mean everything...and VB uses COM, but it hides EVERYTHING about interfaces (paradoxical me thinks), as a lot of VBers are finding moving to .NET and C# in particular.
Glad I could help and it worked out.

No wuckers Mick  :-D

Cheers,
Glenn.