By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,893 Members | 1,231 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,893 IT Pros & Developers. It's quick & easy.

Using a C++ COM DLL in C#

P: n/a
I need to use a pre written C++ COM dll to interface to a TAPI Service
from my C# Application and was wondering the best way of using that dll
in C#.

I am able to access the methods of the DLL by adding a reference with
the tlb file but have also read articles re creating an intermediate dll
using the TlbImp utility and then referencing that in the C# project.

I am really looking for advice in what would be the best way about doing
this task.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Stuart,

Both methods will pretty much do the same thing. If you add a reference
to the TLB file, it actually creates the interop dll for you, and references
that. It calls the same code that TLBIMP calls to generate the managed
assembly.

In larger environments, where the project is shared (and you don't want
to have each developer creating their own interop dll), it's probably better
to use TLBIMP and set a reference to that (you also have more control over
it, and can sign it, if you need to).

In the end though, they produce the same output (for the most part).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Stuart Ferguson" <st**************@btinternet.com> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl...
I need to use a pre written C++ COM dll to interface to a TAPI Service
from my C# Application and was wondering the best way of using that dll
in C#.

I am able to access the methods of the DLL by adding a reference with
the tlb file but have also read articles re creating an intermediate dll
using the TlbImp utility and then referencing that in the C# project.

I am really looking for advice in what would be the best way about doing
this task.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

P: n/a
Are there any memory management issues that need to be handled manually
or does the auto memory management handle everything.

Stuart

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a
Stuart,

You will have to be conscious of the objects you are using. When you
are done with a COM object, you have to release the reference to it. You
can do this by passing the wrapper in managed code to the static
ReleaseComObject method on the Marshal class.

Also, if you call any properties that return objects (basically,
increase the reference count), then you will have to make sure to pass those
to ReleaseComObject when you are done with those as well.

Basically, the reference counting rules still apply in .NET, and you
have to be aware of them.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Stuart Ferguson" <st**************@btinternet.com> wrote in message
news:eM****************@TK2MSFTNGP12.phx.gbl...
Are there any memory management issues that need to be handled manually
or does the auto memory management handle everything.

Stuart

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

P: n/a
Are there any memory management issues that need to be handled manually
or does the auto memory management handle everything.

Stuart

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

P: n/a
Could you send me an example of some code allocating and deallocating
the memory using the method u specified ?

Thanks

Stuart
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.