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 AndyMartin458 · Oct 11, 2013 at 12:49 AM · c#iosbugpluginsdllimport

Why can't Unity use DLLImport twice for overloaded functions?

I've come across an issue where a library uses DLLImport two times for a function that is overloaded. I am building for iOS. Unity throws this when I try to build "Error building Player: SystemException: Duplicate native method found : BASS_MIDI_StreamCreateFileMemory. Please check your source carefully."

I did a simple example with my own functions (where I was careful to not use the same parameters), and Unity refuses to compile. Is this only a limitation for ios? It seems to build OK for OSX.

Here is the example .mm file

 extern "C"
 {
     int StreamCreateFileMemory(bool mem, IntPtr memory, long offset, long length, int flags, int freq)
     {
         return 0;
     }
     
     int StreamCreateFileMemory(bool mem, byte[] memory, long offset, long length, int flags, int freq)
     {
         return 0;
     }
 }

Here is the .cs

 using UnityEngine;
 using System.Collections;
 
 using System;
 using System.Runtime.InteropServices;
 
 public class tests : MonoBehaviour 
 {
     [DllImport("__Internal"]
     private static extern int StreamCreateFileMemory([MarshalAs(UnmanagedType.Bool)] bool mem, IntPtr memory, long offset, long length, int flags, int freq);
     
     [DllImport("__Internal")]
     private static extern int StreamCreateFileMemory([MarshalAs(UnmanagedType.Bool)] bool mem, byte[] memory, long offset, long length, int flags, int freq);
 }

Is there any way around this silly design issue? Unity should be smart enough to handle this if other projects using the MonoFramework are capable.

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

2 Replies

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

Answer by Tarlius · Oct 11, 2013 at 07:20 AM

It sounds like the problem is compiling in Unity, and not xcode. If this is the case, you could simply write a wrapper class plugin and call that. Ie: instead of calling the closed source plugin directly from unity, make another native plugin and call it via that. I'm not too up on plugin development syntax and my Unity is frozen atm so this probably won't compile, but something like this:

 public class tests : MonoBehaviour {
     [DllImport("__Internal"]
     private static extern int StreamCreateFileMemoryWithIntPtr([MarshalAs(UnmanagedType.Bool)] bool mem, IntPtr memory, long offset, long length,     int flags, int freq);
 
     [DllImport("__Internal")]
     private static extern int StreamCreateFileMemoryWithByteArray([MarshalAs(UnmanagedType.Bool)] bool mem, byte[] memory, long offset, long length, int flags, int freq);

}

 extern "C" {
     int StreamCreateFileMemoryWithIntPtr(bool mem, IntPtr memory, long offset, long length, int flags, int freq)
     {
        return StreamCreateFileMemory(mem, memory, offset, length, flags, freq);
     }
 
     int StreamCreateFileMemoryWithByteArray(bool mem, byte[] memory, long offset, long length, int flags, int freq)
     {
        return StreamCreateFileMemory(mem, memory, offset, length, flags, freq);
     }
 }
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 AndyMartin458 · Oct 11, 2013 at 09:47 PM 0
Share

I see what you're doing here. That might ultimately be the solution, but it's a closed source library that I can't directly modify like that. That being said, there is an iOS version that perhaps I could take the time to go through and wrap.

avatar image
1

Answer by dannyskim · Oct 11, 2013 at 01:36 AM

I could be wrong as my C isn't exactly up to date, but I don't believe C method overloading exists in a normal context. I don't think it would be worth your time and effort to create such functionality yourself, so your best bet is to just overload your C# methods, and then call the corresponding C method accordingly.

Comment
Add comment · Show 3 · 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 AndyMartin458 · Oct 11, 2013 at 01:47 AM 0
Share

C++ method overloading does exist, and I believe that they exist in C as well. C just can't distinguish between native types. I can't change the functions because it is being used within a closed_source library that way.

avatar image Tomer-Barkan · Oct 11, 2013 at 06:51 AM 0
Share

You're wrong I'm afraid. C++ is object oriented, but C is not. Hence there is no method overloading in C. I see no choice than turning to the owner of the library and letting him know that it doesn't work on IOS and asking him to fix.

avatar image AndyMartin458 · Oct 11, 2013 at 09:46 PM 0
Share

The extern "C" just keeps the C++ function name intact. I guess my question didn't explicitly say that the functions were C++, but they are (.mm can mix C++ and Objective-C). The library owner says that the ios library works in his version of $$anonymous$$ono.

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

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

Related Questions

Distribute terrain in zones 3 Answers

Bug with EtceteraGUIManager.cs . 1 Answer

TimeSpan error on ios platform 2 Answers

how to pass unicode text from C# to Objective-C 1 Answer

Multiple Cars not working 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