Is it posible to create COM in .Net C#

  • Thread starter Thread starter chinthamani
  • Start date Start date
C

chinthamani

Hai
I want to create a COM in C# .Net, is it posible to create a COM in C#
Net, if how can we create a COM in C# .Net.
Regards
S.Vinodh Noel
(Bangalore)
 
I want to create a COM in C# .Net, is it posible to create a COM in C#
Net, if how can we create a COM in C# .Net.
Yes, but the .NET must be installed in order to run those COM components.
 
chinthamani said:
Hai
I want to create a COM in C# .Net, is it posible to create a COM in C#
Net, if how can we create a COM in C# .Net.
Regards
S.Vinodh Noel
(Bangalore)

Building COM components with .NET is tricky business. Components need
_strong names_ and must be placed in the GAC. After all that they won't run
on older computers. It would be great if C# could be used to make _native_
COM components. I suspect it is possible in _unsafe_ mode with a very large
amount of work.

The last time I made .NET components and exposed them to COM the app ran
very slowly. What can cause this and has the performance improved? I used
version 1.0.

David
 
You can create a COM wrapper with tlbexp.exe, but the code will still require
the .NET platform to run. As a shortcut regasm.exe allows you to create the
wrapper and register it.

You can also reduce the footprint of .NET with this:
http://www.remotesoft.com/linker/index.html

You will still have to have parts of the Framework, however. And, I am not
sure how this bodes with Microsoft. Either way, you will have to create a COM
wrapper.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
apm said:
Building COM components with .NET is tricky business.
No, it's not. Actually it's just as simple to build COM components in .NET
than it is in VB6 f.i. The only tricky thing is to keep an eye on the
requirements imposed by COM.

Components need
_strong names_ and must be placed in the GAC. After all that they won't
run on older computers.
Not true, your private assemblies do't have to be signed and they don't have
to be in the GAC. Public assemblies can better be signed (but this is not
imposed), but don't have to be in the GAC either, you can register them
using the /codebase option.

It would be great if C# could be used to make _native_
COM components. I suspect it is possible in _unsafe_ mode with a very
large amount of work.
C# is targetting a managed environment, building native code is not what it
was designed for, so building native COM was certainly not why .NET was
invented for, why should it, there are still tools arround to build native
COM (C++, VB6, Delphi, ...).
Building native COM using "unsafe mode" is NOT possible, unsafe doesn't mean
native.
The last time I made .NET components and exposed them to COM the app ran
very slowly. What can cause this and has the performance improved? I used
version 1.0.

Transitioning between managed/unmanaged code has some overhead, but when
done correctly , this overhead is negligible.


Willy.
 
Transitioning between managed/unmanaged code has some overhead, but when
done correctly , this overhead is negligible.

Sometimes the overhead is negligible. Sometimes it is not negligible. It
turns out that some of the most efficient means of transfering information
among COM components is very inefficient when a COM component transfers that
information to a .NET component. Sometimes this is not important. Sometimes
it is important. Sometimes the only way to do it "correctly" involves
writting a lot of "unsafe" code.
 
apm said:
Sometimes the overhead is negligible. Sometimes it is not negligible. It
turns out that some of the most efficient means of transfering information
among COM components is very inefficient when a COM component transfers
that information to a .NET component. Sometimes this is not important.
Sometimes it is important. Sometimes the only way to do it "correctly"
involves writting a lot of "unsafe" code.

Unsafe code relates to the usage of pointers in C# to speed-up array
accesses, but this has nothing to do with COM interop. COM interop is fully
integrated in the CLR which takes care of parameter marshaling and interface
marshaling when cross-apartment calls are involved, and it's this marshaling
that takes time. Now, if you take care that COM objects live in the callers
apartment and if you turn-off the security checks performed when calling
into COM or from COM, the call overhead is some 30 instructions per call
(~10-15 nsec. on entry type PC ), this is what I call negligible.

Willy.
 
What security checks are there and how can they be turned off?

When an array of 10,000 double is passed from COM to .NET it is copied
(passed by value). In order to make it behave like an array passed by
reference the array is copied again when control returns to COM. COM
components all running in the same process will pass arrays by passing a
reference. This takes very little time because one pointer is passed. When
COM passes to .NET 10,000 doubles are copied twice unless the default
marshaling is overridden.
Now, if you take care that COM objects live in the callers apartment

I'd like to know how to run a COM object in a .NET object's appartment.

and if you turn-off the security checks performed when calling
 
apm said:
What security checks are there and how can they be turned off?

When an array of 10,000 double is passed from COM to .NET it is copied
(passed by value). In order to make it behave like an array passed by
reference the array is copied again when control returns to COM. COM
components all running in the same process will pass arrays by passing a
reference. This takes very little time because one pointer is passed. When
COM passes to .NET 10,000 doubles are copied twice unless the default
marshaling is overridden.


I'd like to know how to run a COM object in a .NET object's appartment.

and if you turn-off the security checks performed when calling

You can apply:
[System.Security.SuppressUnmanagedCodeSecurity]
in order to suppress a security walk when calling into COM (or unmanaged
code) , note that this is not relevant when calling into .NET as unmanaged
code knows nothing about code access security.

Array's are always copied when calling into .NET from COM, see your other
thread for a more detailed answer.

Willy.
 

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

Back
Top