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 diplojocus · Mar 26, 2012 at 05:48 AM · c# dll

Passing a string as a const char* to C++ library plugin

Hi,

I have a C++ audio library (ZenGarden) that I'm running as a plugin in Unity, this library opens and plays back Pure Data patches.

I'm trying to pass the filepath of a patch to open as a const char* to a function declared in the imported C++ library, but struggling on converting it correctly.

The function is defined as follows in the C++ library:

    ZGGraph *zg_context_new_graph_from_file(ZGContext *context, const char *directory, const char *filename);
 

And in the C# script as follows:

     using UnityEngine;
     using System;
     using System.Runtime.InteropServices;
     using System.IO;
     
     public class ZGUnity : MonoBehaviour {
     
           [DllImport ("__Internal")]
             private static extern IntPtr zg_context_new_graph_from_file(IntPtr context,
                 [MarshalAs(UnmanagedType.LPStr)]String directory,
                 [MarshalAs(UnmanagedType.LPStr)]String filename);
     
         void Awake () {
                 IntPtr graph = zg_context_new_graph_from_file(context, Application.dataPath, "/ball.pd");
           }
 }

When building the app on an iPad it crashes on the splash screen. If I comment out the code in Awake() it runs fine.

I've found a few others having similar issues but none of the suggested solutions have worked for me, for example. I've tried just declaring it as a string, looked at the StringBuilder class and marshalling (as seen in the code I've posted above). I'm very new to C#, if anyone has any pointers I'd much appreciate your input.

Thanks, Joe

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 henkboom · Mar 26, 2012 at 04:13 PM 1
Share

Have you tried it on a stub C function that just prints its arguments, to make sure it's the binding itself causing problems?

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Our game's Assembly-CSharp.dll size is too big. 1 Answer

Run into compile error because of 3rd party DLL referencing UnityEditor. How can I fix this? 1 Answer

NullReferenceException in a wrapper 0 Answers

InvalidProgramException: Invalid IL code in System.Runtime.Remoting.Channels.Ipc.IpcClientChannel:get_ChannelName (): IL_0000: ret 1 Answer

c# database connection on debian server 0 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