Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by arn.zhan · Dec 25, 2011 at 02:46 AM · c#dllc++wrapper

How to use native C++ classes in Unity

Hi everyone,

I've searched for days but couldn't find a answer for this question.

Limitations apply to my case:
1. Target platform: PC
2. Unity Indie
3. Having the C++ source code.

I'm currently using a C# wrapper dll which depends on native dlls and it works well in Unity Indie (it's OpenCvSharp, if you like to know). Thus please do not answer Pro is required and see the Plugin page.

So I believe I can do it too. Compile the C++ dll and create a C# wrapper dll for it. I'm trying to do this with SWIG. I putted all SWIG generated .cs files in a VS project targeting .Net_2.0, compiled a C# dll, put it in Unity and Mono editor can auto-complete methods in the class. Is it working?

No, the compiler complains:

EntryPointNotFoundException: SWIGRegisterExceptionCallbacks_MaxFlowGraph

MaxFlowGraph is the namespace of C++ code.

And I'm stuck here. Any help will be appreaciated. MERRY CHRISTMAS!

--------------Update---------------

Thank you Dreamora.

I finally got the compiler errors away, but now facing an other problem.

When I do this:

 Graph g = new Graph();
 int k = g.AddNode();

It's fine, and I tried Debug.Log(k) and it seems working right. So I think I can call functions and get returning values.

But when I try to pass a value to the dll, Unity will crash:

 g.AddNode(num_of_nodes);

No idea why I can receive parameters but cannot pass them.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dreamora · Dec 26, 2011 at 04:54 PM

if you use a c# -> native code wrapper you have to put the native code library in the right place (which isn't Plugins due to your inbetween layer to trick out the broken interop services check of unity). the easiest place is a folder thats in the global path environment variable, if thats not fine you have to tinker with it to find the right place as it depends on the referencing in your wrapper.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image arn.zhan · Dec 27, 2011 at 12:05 PM 0
Share

Thanks Dreamora, I did placed the native C++ dll in the right place, it turns out that I should deal with those SWIGTYPE_p_{TYPE}. Fixed it and now facing new problem. I guess my new problem is more general... not sure.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Using a fixed size pointer in Unity C# with a C++ external function 0 Answers

C++ plugin for Unity “EntryPointNotFoundExeption” 0 Answers

How to get Unity to detect my own touch events 0 Answers

Chain of dependency dll's not loading correctly. 1 Answer

Best approach to C++ integration into a script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges