Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I am using any API which is created in c# or VB, can this API be used in either Managed Code or Unmanaged Code?
Posted
Updated 5-Aug-11 0:00am
v2
Comments
Slacker007 5-Aug-11 6:01am    
Edited for readability and tags.

Yes. MSDN[^] to the rescue!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Aug-11 6:11am    
Great reference, my 5.
Did you see my solution and references (I offered those before, very interesting CodeProject article and really cunning yet robust method strictly based on the CLR standards.)
--SA
I assume you mean C# and VB.NET (even if you mean VB, let's forget it).

Basically, it can be used only in managed code, by referencing in the project or by loading it during run time using System.Reflection.Assembly.

You can develop mixed-mode assemblies which can be used as both .NET Assembly and a regular unmanaged DLL, but C# and VB.NET are not good enough to do that (but C++/CLI and IL can do it).

However, there is a very cunning solution to convert existing .NET Assembly in mixed mode and exporting some managed method to unmanaged. The idea is to disassemble the assembly to IL, modify IL code and re-assemble. This process can be automated.

Here are the CodeProject articles offering such solutions:
Unmanaged code can wrap managed methods[^],
How to Automate Exporting .NET Function to Unmanaged Programs[^].

See also my past solutions explaining the idea:
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
Call Managed DLL written in C# from Unmanged Code VC++[^].

—SA
 
Share this answer
 
Comments
Slacker007 5-Aug-11 6:53am    
Nice answer.
Sergey Alexandrovich Kryukov 5-Aug-11 14:52pm    
Thank you very much,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900