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
1
Question by Ashkan_gc · Jan 09, 2010 at 05:08 PM · dllexternal-librarieswrapper

how to create a wrapper for C++ class libraries

i want to use some C++ libraries in unity. unity just can use C style function libraries. how should i wrap the classes? think i want to use physx cloth or any other library. unity already do that with physx and some other libraries so it's possible. i know that C++/CLI is not an option here because they are mixed assemblies and mono doesn't support them. my target is windows. some of game libraries are static .lib files and some of them are DLLs. most of the third party game related libraries are C++ class libraries so we all need this. i know about some tools to create wrappers but i want to do that myself programmaticly because tools don't work well always.

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
1
Best Answer

Answer by jonas-echterhoff · Jan 09, 2010 at 05:30 PM

When you are targeting Mac/PC standalones, then you can write plugins for Unity in C - and use those to access your C++ libraries.

Read the docs to learn how.

Comment
Add comment · Show 6 · 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 Ashkan_gc · Jan 10, 2010 at 03:23 AM 0
Share

i am targeting windows and i know what you said but i want to know what C program should i write to wrap a class library correctly? shoul i keep static references to instances of classes or ...?

avatar image jonas-echterhoff ♦♦ · Jan 12, 2010 at 12:15 PM 2
Share

I guess there a multiple approaches here, depending on what you need. If you just need to access a single manager class, you can just keep a static reference to that in your C program. If you need to expose the use of instances of classes to C#, you could just cast the instance pointer values to ints and pass those to C# and then back to C++.

avatar image Ashkan_gc · Jan 16, 2010 at 06:21 PM 0
Share

can you tell me how unity uses physx or openAL? is there any general approach for creating wrappers?

avatar image jonas-echterhoff ♦♦ · Jan 17, 2010 at 03:07 PM 0
Share

The use of PhysX or OpenAL (now F$$anonymous$$OD) in Unity is somewhat different, as these libraries are not wrapped and accessed from the C# code, but are part of Unity's C++ core - so the situation is not really comparable.

But, really, wrapping such libraries to C# should be well possible - for OpenAL, which is in C, you could directly map every function to C# as they are - for C++ libraries like PhysX, you can just pass the object instance as another parameter.

avatar image Ashkan_gc · Jan 18, 2010 at 02:17 PM 0
Share

you are right. thank you so much. i'll take a look at wrapper generators like swig and also i should take a look at some open source wrappers. the real library that i love to wrap is a weather library called simulweather. i encourage you to take a look at simulweather you might love to have such an advanced weather system in unity 3 :)

Show more comments

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distributing Precompiled Scripts 1 Answer

Unity TestTools and External DLL conflict? 1 Answer

Read Files from a folder -> Load their icons as Textures 1 Answer

How to set unity for finding the c# dll? 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