Jump to content
  • Advertisement
Sign in to follow this  
Greg K

[.net] VC++ DLL's in C#

This topic is 5410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I will start off by saying that I am extremely new to c# so sorry if these questions are fairly simple. What I am trying to do is load a dll that was compiled in vc++.net and use it in c#. Is this even possible? The dll exports a class. Can I use the class in c# the same as if I were using c++? -Greg

Share this post


Link to post
Share on other sites
Advertisement
Depends, if it was managed C++, then sure.
However, with unmanaged C++ there is currently no way to import C++ classes to .net without writing a managed wrapper.

Share this post


Link to post
Share on other sites
Not for C++ classes
Functions marked extern "C" can be imported using DllImport however.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can mark all the exported functions in the dll with the dllexport attribute. This will allow you to then import them into a c# program. I wrote a blackjack program in C# using the cards.dll that comes with windows XP. I believe you can add a reference directly to the dll using the reference manager in the IDE (right click on the references folder in your project workspace window)

Share this post


Link to post
Share on other sites
Those are C functions in the cards.dll. Aka, marked extern "C". A C++ class is quite different.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
okay, one more question...
After writing a wrapper class for my unmanaged c++ stuff in the dll, how do I get c# to see/use that class? I know how to add the dll to c# (in the references) but then how do I create an instance of my wrapper?


in my dll:
public __gc class ManagedMithrill_Api
{
private:
Mithrill_Api* m_Mithrill;
public:
static void Create();
static void Destroy();
};

Share this post


Link to post
Share on other sites
Oh, it seems I fixed it. I put my object in a namespace, added using mynamespace; in c# and then just used the object. Very easy... Now I am trying to send a window handle back to my dll so it can use it as it's directX window.
-Greg

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!