how to export a .net dll function

  • Thread starter Thread starter Ricardo Silveira
  • Start date Start date
R

Ricardo Silveira

There is any way to access a .net dll function (C#) from a C++ program?

Thanks.

Ricardo
 
The only way to use a function in a .NET dll from C++ is to use Managed C++.

Chris
 
How about using COM Interop and creating a COM Callable Wrapper for the C#
dll. Then access it just as you would any other COM object from your C++
application.

David
 
Thats true, forgot that one.

Chris

dm_dal said:
How about using COM Interop and creating a COM Callable Wrapper for the C#
dll. Then access it just as you would any other COM object from your C++
application.

David
 
There is any way to access a .net dll function (C#) from a C++ program?

Thanks.

Creative round-tripping.

Basically:

1. run ildasm on the assembly to produce a set of resource files and a
disassembly in a .il file
2. fix up the .il file to include the necessary directives
3. run ilasm on the assembly file, rebuilding the assembly with the new
directives

There's an article about it here:
http://www.blong.com/Conferences/BorConUK2002/Interop1/Win32AndDotNetIntero
p.htm

Beware of the wrapping in the url. Also, note that while the article is
written by a Delphi guy for Delphi it will work nicely with your C#
assemblies.
 
Lasse Vågsæther Karlsen said:
Creative round-tripping.

Basically:

1. run ildasm on the assembly to produce a set of resource files and a
disassembly in a .il file
2. fix up the .il file to include the necessary directives
3. run ilasm on the assembly file, rebuilding the assembly with the new
directives

There's an article about it here:
http://www.blong.com/Conferences/BorConUK2002/Interop1/Win32AndDotNetIntero
p.htm


See my other answer to this question. Exporting methods from an assembly is
a bad thing in the current version of the framework. It will cause
deadlocks, so don't do it. The only safe way is to use the COM interop layer
through the COM Callable Wrapper.

Richard
 
See my other answer to this question. Exporting methods from an
assembly is a bad thing in the current version of the framework. It
will cause deadlocks, so don't do it. The only safe way is to use the
COM interop layer through the COM Callable Wrapper.

Richard

Thanks for the heads up. I haven't actually done much with this except for
doing a test project to check it. Didn't know there was problems with it,
but now I'll just let this slide :)

Will .net 2.0 allow for safe export of functions from a dll, even from C# ?
 
See my other answer to this question. Exporting methods from an assembly
is
a bad thing in the current version of the framework. It will cause
deadlocks, so don't do it. The only safe way is to use the COM interop layer
through the COM Callable Wrapper.

Your statement assumes that everything does the exporting the same way as
Managed C++. Creative round tripping using Inverse P/Invoke does not
manufacture an exported DLL entry point, so far as I can tell. The same is
true with Delphi for .NET, which also supports unmanaged exports by simple
Inverse P/Invoke. I think the deadlock thing is a Managed C++ specific issue
due to the extra code generated when you export a routine

- Brian Long (www.blong.com)
 
Your statement assumes that everything does the exporting the same way
as Managed C++. Creative round tripping using Inverse P/Invoke does
not manufacture an exported DLL entry point, so far as I can tell. The
same is true with Delphi for .NET, which also supports unmanaged
exports by simple Inverse P/Invoke. I think the deadlock thing is a
Managed C++ specific issue due to the extra code generated when you
export a routine
<snip>

Sorry for the late reply but I've been having a vacation.

Is there any way to test for this deadlock issue ?

Could anyone email me a copy of a C++ dll with an exported entry pointed so
that I could disect it ? I Don't have C++ install nor do I know enough
about C++ and compiler directives to trust myself to be able to do it
correctly.
 
Back
Top