cs and c++ code

  • Thread starter Thread starter tom
  • Start date Start date
T

tom

do you think this is going to be tricky:
I wanna write
some code (GUI stuff) in c#, and
some code in c++.

I'm wondering:
a) .net uses .dll files differently (seems to include a lot (all) the
definitions
I would expect in a shared lib (but obviously) I dunno much about this;
so
b) would i expect a VS C++ .dll to easily be called from a C# primary .exe

caveat: I know many of my foundational assumtions are way wrong, but
I'm gonna get there in the end. Thanks for your help.
tom
 
Hi Tom,

If you create a managed C++ dll then the integration is seamless to the
managaged classes.

However if you are refering to a unmanaged C++ dll then you will have to use
the platform invocation services (P/Invoke). If you intend to use an
unmanaged C++ class from C# you are in for a surprise, though it is doable
it is a ton of work. Firstly I would recommend creating a COM wrapper for
the C++ class and consume that from C#. Otherwise, you need to create a
factory method to create the unmanaged C++ instance as well as a method to
free the instance, then create a P/Invoke extern for each member using the
CallingConvention.ThisCall calling convention, You would then most likely
end up writting a C# class to hide all the manual passing of the this
pointer. Really not what I would generally call fun.

Hope this helps

Chris Taylor
 
Back
Top