invoking C# function from C++

This is a discussion on invoking C# function from C++ within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, I have developed a COM component using C++. And I need to invoke some functions in another DLL ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    invoking C# function from C++

    Hello everyone,


    I have developed a COM component using C++. And I need to invoke some functions in another DLL which is implemented in C#. I am wondering whether there are any tutorials or samples of how to do this correctly and safely?

    I have this question because I noticed that the data types in C++ and C# are not the same -- how to make them compatible? This is the most of my concern.


    thanks in advance,
    George

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    Moved from C to C++
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    The easiest way without a doubt would be to use C++/CLI and just call the functions.

    If that's not an option, you must compile the C# DLL with COM interop enabled, so that the C# classes are exposed as COM objects. You can then use COM or ActiveX calls into the DLL, which is far less convenient. But you might be able to use VC++'s COM importer to make it easier.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21