Jump to content
  • Advertisement
Sign in to follow this  
Shawn19841006

Want to use unmanaged c++ library in managed c++ project

This topic is 3625 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

As title that I want to use unmanaged c++ .lib file in managed c++ project, is it possible to directly do this? I found some information that says it can work but by my personal test it just produced link error. Need help here. Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
Use pragmas to mark unmanaged code like:

#pragma unmanaged
#include "yourlibheader.hpp"

YourUnamangedClass instance;
#pragma managed


You may want to write wrappers to your unmanaged code (for example to use properties or to convert some of the parameters like strings)

EDIT: oh I forgot: You might need to change some settings in the project. Notably /clr:pure to /clr only (Common Language Runtime Support option).

You may also want to look at __nogc keyword.

Share this post


Link to post
Share on other sites
Hey, so I just changed the project setting from /clr:pure to /clr and then it
just worked!

I'm new to .net platform so I don't really know what those settings mean but I will definitely look it up.

I'm trying to use managed c++ to build my tool but I found others mostly write
wrappers for their c++ engine and do the tool in c#. But I'm really lazy to write
the wrappers...

Hope things go well with managed c++ for my tool...

Thanks a lot.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!