Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 WhYmE_91 · Oct 03, 2017 at 12:42 PM · pluginnative pluginc++

C++ native plugin Failed with error '%1 is not a valid Win32 application

Hello,

I have been trying to get a native plugin written in C++ to work in Unity. This is my first time writing such a plugin, so I was playing around with some test code to see if I could get it working. However, I am running into an issue I can't wrap my head around. Unity reports an error with the use of my plugin whenever I use a C++ style convention, like new (I have no experience writing code in C, so apologies if that statement is not true).

Below is the C++ code I am using:

 #define UNITY_EXPORT __declspec(dllexport)    
 int value = 0;    
 class AA {
 public:
     int index;
 };    
 static AA* aaa = 0;
 
 static void DoInit(){
     aaa = new AA();
 }
 
 extern "C" {
     UNITY_EXPORT void A(int x){
         value = x;
     }
     UNITY_EXPORT int B(){
         return value;
     }    
     UNITY_EXPORT void Init(){
         DoInit();
     }
 }

And this is the MonoBehaviour script: public class TestDLL : MonoBehaviour {

     [DllImport("libUnitySimpleTest", EntryPoint="A")]
     public static extern void A(int x);
 
     [DllImport("libUnitySimpleTest", EntryPoint="B")]
     public static extern int B();
 
     [DllImport("libUnitySimpleTest", EntryPoint="Init")]
     public static extern void Init();
 
     // Use this for initialization
     void Start () {
         Init ();
     }
     
     // Update is called once per frame
     void Update () {
         A (2);    
         int r = B ();
         transform.position = new Vector3 (r, 0.5f, 0);
     }
 }

The error message is: "Failed to load 'Assets/Plugin/[pluginname].dll' with error '%1 is not a valid Win32 application.

After a lot of trial and error, I figured out that this error happens when I do the "aaa = new AA();" call. If I comment this line, it works fine. Likewise, if I try to for example create a char* array using the new keyword, the error appears, but creating the array using malloc() works fine.

Any idea why this happens or how I can fix it?

If it matters, I am not using the Pro version of Unity.

Thanks in advance.

Yme

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

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

70 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 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 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 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

How can I get the Native Plugin example to work on Unity 5? 0 Answers

Can I code a native plugin for iOS in C/C++? 0 Answers

How to access an Android native plugin in unity ? 0 Answers

IUnityEventQueue - how do I use it? 2 Answers

Realtime C++ Unity Interaction 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