.Net interoperability headache

This is a discussion on .Net interoperability headache within the C++ Programming forums, part of the General Programming Boards category; I got the notion to create a gui interface for some image recognition functions I wrote using the opencv library ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    18

    .Net interoperability headache

    I got the notion to create a gui interface for some image recognition functions I wrote using the opencv library in c++. My plan was to create my gui in c# and call my functions from my old c++ code.
    Im hoping to learn more about the .Net framework and code interoperability.

    However its not as straight forward as I thought, my reading on the msdn website has taken me down paths of learning about com,dll, data marhling and so on, my compiler has the same blank project opened on it for the last 3 days without taking a simple key input. Either interoperability is not as easy as I thought or Im off on a completely irrelevant tangent.

    My questions are, is .Net really worth the hassel?
    Is there any good structured material ,with good examples, showing this process, since all the information Im reading is from many different sources?
    Does anyone have any links to a tutorial that gives an example of coding c++ code and calling it in c#?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    What sort of parameters do your C++ functions take? Would you be passing image data or complicated image structures, or just driving some high-level functions? You need to put your native code into a DLL and then use the [DLLImport] attribute to bring into into .NET land. If your data types are simple, things should for the most part "just work."

    Can you give an example of a function prototype for one of the functions you want to call from .NET?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    18
    Here are a few simple ones
    Code:
    void con2txt(IplImage *img2)
    void vidstop (int event,int x, int y,int flags, void *param)
    void vidtake(int a ,int b)
    I would like to pass some image structure eventually, Im hoping to add more functions.
    TBH my project goal is to make an interface similar/better to what we use in Matlab using simple Opencv functions and then maybe add to the functionality. I am interested to learn how to create dlls and wrappers for some of these functions as I want to take my programming to a more sophisticated level but I'm looking into the Emugu wrapper atm.

    Is there any good books on this kind of thing?
    Last edited by aprop; 02-07-2012 at 04:11 AM.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    2,300
    all of those parameters can be handled by the .Net framework. for the pointers, you can use type IntPtr.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    18
    Quote Originally Posted by Elkvis View Post
    all of those parameters can be handled by the .Net framework. for the pointers, you can use type IntPtr.
    What do you mean by "all of those parameters can be handled by the .Net framework", do you mean I can just insert these functions and code written in c++ and compile it in C#?

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    2,300
    no, not exactly. you still have to create a native DLL and import its functionality to C# via the DLLImport attribute.

    something like this:

    Code:
    [DLLImport("dllfile.dll", EntryPoint="vidstop")]
    public static extern void vidstop (int event,int x, int y,int flags, IntPtr param);
    that should get you started, and you should be able to figure out the rest.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Headache
    By Neo_C in forum C Programming
    Replies: 2
    Last Post: 06-29-2010, 01:25 PM
  2. interoperability with anything
    By nonoob in forum C Programming
    Replies: 1
    Last Post: 06-23-2009, 10:05 AM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  4. I/O headache
    By Strait in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2005, 11:20 AM
  5. My headache
    By Morgan in forum C Programming
    Replies: 7
    Last Post: 12-03-2002, 02:33 AM

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