- Home /
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
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.
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.
Thanks, that was it. I added [$$anonymous$$ashalAs(UnamangedType.LPWStr)]
and it worked.
Thanks a lot.