Can I expose my API/COM interfaces as .Net interfaces?

R

rakefet

Hi.

I'm really new to this world of .Net so your help would be most
appreciated...

We have API and COM interfaces developed in c. We would also like to
supply a .net interface to our clients.

Searching - I found many new words :) like .Net wrapper, Assembly...
but I couldn't find a clear cut answer -
What do I need to do in order to expose a .net interface?

What is the difference between "real" .NET APIs and having some kind of
wrapper around API or COM interface...?

Thanks in advance
Rakefet
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

To use COM you need to do nothing, from VS you can access the COM classes
from Projects/Add References then VS will create the wrapper for you. If you
want to provide these wrapper you can do so, check
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callcomcomp.asp

Now the real problems are the APIs, I assume you mean native win32 dlls,
with this you cannot use the above approach, In this case classes in .NET
that mimics those dlls, inside the classes you will need to P/Invoke the
methods. If you define structures you will need to define them again in
..net.
P/Invoke can be tricky if you are using complex structures or calling
methods. You will need to read a lot about it, start with
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/ also take a look at
www.pinvoke.net , very useful !!! you will get ideas of hwo you can marshall
parameters.


Cheers,
 
B

Bob Powell [MVP]

You can add reference to a COM DLL to your project and the IDE will create
an interop wrapper assembly for you. It's a very simple and painless
process.

The difference will be that the COM interop assembly will set up sensible
managed / unmananged marshalling for you and provide .NET enumerations and
structures that you can use with the COM objects in your DLL. You can of
course do all of this by hand if you wish but generally the IDE which uses
TLBImp internally does a pretty good job.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
D

Derrick Coetzee [MSFT]

We have API and COM interfaces developed in c. We would also like to
supply a .net interface to our clients.
What do I need to do in order to expose a .net interface?

Hi Rakefet. This is a common question. There are tools included with .NET
(tlbimp.exe) and Visual Studio (Add Reference->COM tab) to facilitate this
scenario. You can read more about using COM components from .NET at the
following URLs:

Interoperability of COM components with .NET
http://www.c-sharpcorner.com/Code/2004/Aug/Interoperabilityin.NET.asp

COM Interoperability in the .NET Framework
http://aspnet.4guysfromrolla.com/articles/010803-1.aspx

I hope this helps.
 

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