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 Mike-B · May 15, 2015 at 12:47 AM · iospluginil2cpp

What difference IL2CPP make for native plugins?

I have an iOS plugin for web requests. It is a library actually developed for mono. The plugin works great with the Mono option but does not work when built with IL2CPP option. The problem occurs when passing strings from my app to the plugin: the url generated in my app is passed to the plugin and shows as Chinese characters on the native side. As this is a third-party plugin, I can't access the source code.

I filed a bug report: http://fogbugz.unity3d.com/default.asp?694867_1jim6k10v5vs7he8

Here is the managed declaration of the extern function:

 private static extern System.IntPtr CkHttpU_QuickGetObjW(System.IntPtr pObj, string url);
 
 [DllImport(ChilkatConst.DllPath, EntryPoint = "CkHttpU_quickGetStrW", CharSet = CharSet.Unicode)]

Does that make sense to someone? what should be changed natively to handle those strings correctly?

thanks

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

Answer by JoshPeterson · May 15, 2015 at 11:32 AM

In general, marshaling to native code via p/invoke works the same for Il2CPP as it does for Mono. Note that if the plugin is calling directly to Mono using the embedded API (mono_* functions), then it will have a problem. If you have the source code for the plugin, you may want to have a look.

If the problem is related to a p/invoke issue though, could you provide the managed declaration of the extern function, as well as the declaration of the native function here? It might be that something in the p/invoke signature that we can correct. Thanks.

Edit:

So after looking at the file in bug report it seems that you may have posted the wrong DLLImport attribute here. I think the one for this function is actually this:

     [DllImport(ChilkatConst.DllPath, EntryPoint = "CkHttpU_QuickGetObjW", CharSet = CharSet.Unicode)]
     private static extern System.IntPtr CkHttpU_QuickGetObjW(System.IntPtr pObj, string url);

(Note that the attribute must be above the declaration, not below it). In any case, it is difficult to tell what the problem is without knowing the native interface of the library itself. As a test, could you please try modifying the extern definition of the function so that it explicitly mentions how to marshal the string? There are two different variation to try:

     [DllImport(ChilkatConst.DllPath, EntryPoint = "CkHttpU_QuickGetObjW", CharSet = CharSet.Unicode)]
     private static extern System.IntPtr CkHttpU_QuickGetObjW(System.IntPtr pObj, [MashalAs(UnamangedType.LPStr)]string url);

and

     DllImport(ChilkatConst.DllPath, EntryPoint = "CkHttpU_QuickGetObjW", CharSet = CharSet.Unicode)]
     private static extern System.IntPtr CkHttpU_QuickGetObjW(System.IntPtr pObj, [MashalAs(UnamangedType.LPWStr)]string url);

I suspect that at least one of these will work. Could you please try them and let me know? Thanks.

Comment
Add comment · Show 2 · 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 Mike-B · May 17, 2015 at 10:22 PM 0
Share

I don't have the source code as it is a third-party plugin, and I don't have the native declaration either. I edited the question to include the managed declaration of the extern function. Thanks.

avatar image Mike-B · Jun 02, 2015 at 04:53 AM 0
Share

Thanks, that was it. I added [$$anonymous$$ashalAs(UnamangedType.LPWStr)] and it worked.

Thanks a lot.

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

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

Related Questions

IL2CPP C# passed ref float[] to C++ can't get right result 1 Answer

Callbacks from C to C# are not working in 5.4.0f3 1 Answer

I18N.dll and I18N.CJK.dll don't work with IL2CPP 1 Answer

How do I remove plugin for iOS builds only 1 Answer

Call Unity class in XCode 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