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 chase cobb · Aug 06, 2013 at 05:24 PM · c#c++nativevoidpointer

Equivalent of a void ** in from external library?

I'm working with an external library where a function has a void ** in its signature as an argument. How would one match this signature in c# without using unsafe code? Any help would be greatly appreciated!

Comment
Add comment · Show 1
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 VolureDarkAngel · Aug 08, 2013 at 05:22 PM 0
Share

What function are you trying to work with. If it is an API call there is a possibility that this void** is actually a pointer to a structure, or a pointer to an array. $$anonymous$$nowing the api call would help in producing C# code for it.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by chase cobb · Aug 09, 2013 at 11:21 PM

This is what I was looking for.

  • http://msdn.microsoft.com/en-us/library/aa328695(v=vs.71).aspx

  • http://www.mono-project.com/Interop_with_Native_Libraries

  • http://stackoverflow.com/questions/359541/interoping-between-c-sharp-and-an-unmanaged-c-library

There is also a tool to handle the data-type conversions automatically. PInvoke Signature Toolkit - > http://clrinterop.codeplex.com/releases/view/14120

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 Xtro · Aug 10, 2013 at 02:07 PM 0
Share

Yea. I totally forgot that. I'm sorry. I'd like to see your code block which is consu$$anonymous$$g this function and passing the parameter with IntPtr.

avatar image
0

Answer by Xtro · Aug 06, 2013 at 08:21 PM

Pointers are unsafe. End of story.

You can write a wrapper function which is handling the memory allocations and data movement but it has to be in C++/CLI. Not C#

Comment
Add comment · Show 5 · 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 chase cobb · Aug 08, 2013 at 05:02 PM 0
Share

I know that pointers are unsafe, but cant you normally pass a value in by ref to get the desired functionality from a native function looking for a pointer? For example:

c++:
void Cube(int * x);

c#:
void Cube(ref int x);

avatar image Xtro · Aug 08, 2013 at 05:11 PM 0
Share

No. References are not the same thing. References are referencing a memory block in managed memory. Pointers may or may not be referencing the managed memory or unsafe memory.

You can't cast a pointer into a reference or viceversa.

avatar image Xtro · Aug 08, 2013 at 05:14 PM 0
Share

.Net Wrapper classes and methods for a unmanaged dll gets implemented for this very reason. Wrapper method must create a memory block in the managed memory and copy the data from unsafe memory to managed memory. Then it can pass the newly created reference for the managed memory to the caller method. Wrappers are written in C++/CLI

avatar image chase cobb · Aug 08, 2013 at 05:31 PM 0
Share

I'm very familiar with the way that references and pointers are handled and their differences in c++, it's the managed code that I'm not familiar with. Thanks for the info!

avatar image Xtro · Aug 08, 2013 at 07:03 PM 0
Share

If the info was sufficient please don't forget the mark my post as answer. Thank you :)

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Error CS0023: The '!' operator cannot be applied to operand of type 'void' 1 Answer

Check if a function is no longer being called? 3 Answers


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