interop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a set of classes source in C++ and I want to use those from C#, can
I just make these into a regular DLL and export these and DllImport these
from C# with no problems?

Is it that easy?
 
Hi,

You cannot use DllImport with classes, only with plain C-style functions.
Therefore, you should probably implement a kind of facade API serving as a
bridge between the managed code and the unmanaged object-oriented C++ code.

You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would
also require more effort.
 
Cant I make a mixed mode assembly?

I mean I have the class source here (Its not mine) and can I make a new .NET
assembly in C++ and make it visible to C# that way?



Dmitriy Lapshin said:
Hi,

You cannot use DllImport with classes, only with plain C-style functions.
Therefore, you should probably implement a kind of facade API serving as a
bridge between the managed code and the unmanaged object-oriented C++ code.

You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would
also require more effort.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi,

I have a set of classes source in C++ and I want to use those from C#, can
I just make these into a regular DLL and export these and DllImport these
from C# with no problems?

Is it that easy?
 
I just need the fastest way to get access to these classses in C#
I really dont care for the complexity or s.hitness of the library I have to
use. I just have a few days to get it visible in C# :D




Cant I make a mixed mode assembly?

I mean I have the class source here (Its not mine) and can I make a new ..NET
assembly in C++ and make it visible to C# that way?



Dmitriy Lapshin said:
Hi,

You cannot use DllImport with classes, only with plain C-style functions.
Therefore, you should probably implement a kind of facade API serving as a
bridge between the managed code and the unmanaged object-oriented C++ code.

You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would
also require more effort.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi,

I have a set of classes source in C++ and I want to use those from
C#,
can
I just make these into a regular DLL and export these and DllImport these
from C# with no problems?

Is it that easy?
 
I think it's pretty possible to mix managed and unmanaged code in Managed
C++ projects - so this can really be a viable solution. I haven't done much
Managed C++ programming though (as probably many subscribers to this NG) so
you'd better ask in the more appropriate newsgroup.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I just need the fastest way to get access to these classses in C#
I really dont care for the complexity or s.hitness of the library I have to
use. I just have a few days to get it visible in C# :D




Cant I make a mixed mode assembly?

I mean I have the class source here (Its not mine) and can I make a new .NET
assembly in C++ and make it visible to C# that way?



in message news:[email protected]...
as
a
bridge between the managed code and the unmanaged object-oriented C++ code.

You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would
also require more effort.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

<.> wrote in message Hi,

I have a set of classes source in C++ and I want to use those from C#,
can
I just make these into a regular DLL and export these and DllImport these
from C# with no problems?

Is it that easy?
 
I just need the fastest way to get access to these classses in C#
I really dont care for the complexity or s.hitness of the library I have to
use. I just have a few days to get it visible in C# :D

I would build a COM-wrapper for the C++ code. There are tools that do that
for you. Keep the 'dirt' in the C++-DLL, and the C# code neat (using
com-interop). That way future .NET developers can maintain your code without
them knowing anything about unmanaged code.

- Michael S
 
Im hoping it is, I havnt done much C++/CLI code but there is always a first.

I hope I can just make a new project, include these classes and expose them
somehow.

I dont want to have to implement my own API via a facade or worse, COM
belugh.

Doing COM to me is timewasted, I can use theyre native flatt DLL and port
the actual code myself from C++ to C# worst case.


Im gona try for a mixed mode interop assembly as to me thats why we have
such a feature on the .NET platform.



Dmitriy Lapshin said:
I think it's pretty possible to mix managed and unmanaged code in Managed
C++ projects - so this can really be a viable solution. I haven't done much
Managed C++ programming though (as probably many subscribers to this NG) so
you'd better ask in the more appropriate newsgroup.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I just need the fastest way to get access to these classses in C#
I really dont care for the complexity or s.hitness of the library I have to
use. I just have a few days to get it visible in C# :D




new
.NET
serving
as
a
bridge between the managed code and the unmanaged object-oriented C++
code.

You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would
also require more effort.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

<.> wrote in message Hi,

I have a set of classes source in C++ and I want to use those
from
C#,
can
I just make these into a regular DLL and export these and DllImport
these
from C# with no problems?

Is it that easy?
 
Im gona try for a mixed mode interop assembly as to me thats why we have
such a feature on the .NET platform.

I'm monitoring this thread. Please report on your findings on mixed mode
interop, if you find the time. I haven't tried that myself and are quite
curious of your experience.

Get back to us...

Regards

- Michael S
 
Where can I get these tools because I dont want to end up knee deep in COM
s.hit. I want to modify these classes a little as possible if at all
because they are not maintained by me, they are by a 3rd party.

I havnt got alot of COM expereience.
 
Is it a big job to make these classes a COM component?

Do I just add a IDL file or something or must I modify the code alot?
 
Maybe the most simple solution would be to do the following type of wrapper.


public __gc class SomeWrapper
{
public: SomeWrapper()
{
sc = new SomeClass();
}

public: double someMethod(double num1, double num2)
{
return sc->Add(num1,num2);
}

public: ~SomeWrapper()
{
delete sc;
}


private: SomeClass* sc;
};
 
Back
Top