Calling C# functions from C++? 
Author Message
 Calling C# functions from C++?

How can I write a C# library whose functions can be dynamically invoked by a
C++ program?

Does anyone know where I can find a tutorial on this issue?



Sun, 18 Sep 2005 06:22:42 GMT  
 Calling C# functions from C++?
Dean,

    You can do this in two ways.  The first would be to use Managed
Extensions in C++, which would allow you to call managed code.

    The second would be to export the classes in the assembly as COM
objects, and then create the COM objects in your C++ code and use them in
that manner.

    Hope this helps.

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> How can I write a C# library whose functions can be dynamically invoked by
a
> C++ program?

> Does anyone know where I can find a tutorial on this issue?



Sun, 18 Sep 2005 06:28:39 GMT  
 Calling C# functions from C++?
You can use managed C++:

/* compile with csc /t:library test.cs*/
using System;
public class Test
{
   public void UseMe(){Console.WriteLine("used me");}

Quote:
}

/*compile with cl /clr use.cpp*/
#using <mscorlib.dll>
#using "test.dll"
void main()
{
Test* t  = new Test;
t->UseMe();

Quote:
}

If the client is unmanaged C++ then you need to use COPM interop

1a) regasm test.dll /codebase (this means that the test.dll *must* remain in
the same folder
1b) or give test.dll a strong name (cf) and install it into the GAC (cf
gacutil) then use regasm test.dll
2) tlbexp test.dll to get a type library
3) write a C++ client that uses #import on the type library and treats the
.NET classes as COM classes

Richard

--


Quote:
> How can I write a C# library whose functions can be dynamically invoked by
a
> C++ program?

> Does anyone know where I can find a tutorial on this issue?



Sat, 24 Sep 2005 22:45:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. C# client crashs when calling into Managed C++ which calls unmanaged c++ function

2. Calling Managed C++ function from C# with array parameters

3. Calling Managed C++ function from C# with array parameters

4. calling javascript functions from C# function in ASPX page

5. Call C++ member function from C function ?

6. Calling C++ Functions from C functions under HP and Linux

7. C function calling function in C++ library

8. C functions calling {C++/Ada/...} functions

9. Calling a C++ function from a C function

10. Calling C++ member function through C function callback

11. Newbie: separate big .cs file into small .cs files

12. Call API functions(C#)

 

 
Powered by phpBB® Forum Software