c++ - Adding a Native .dll file from SIMULINK to Visual Studios C# -


i have created .dll file using simulink's embedded coder. (system target file set : ert_shrlib.tlc) builds model_win64.dll. want reference visual studios.

i first tried using "add reference" tool got following error: a reference 'file path\model_win64.dll'

i searched around solution online , getting error cause .dll file being native .dll should use dllimportattribute class https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx

so code have

using system; using system.runtime.interopservices;   namespace gui_interface {     class main     {     [dllimport("modbot_model_win64.dll", charset = charset.unicode)]     public static extern int[] mpc(double x, double y, double theta, double vx, double vy, double vtheta);      public static backgroundworker test()     {         ints = mpc(0, 0, 0, 0, 0, 0);     } } 

and runtime error:cannot marshal 'return value': invalid managed/unmanaged type combination. i've tried reading on managed/unmanaged types can't wrap head around in order solve issue. proposed solutions or info on managed/unmanaged appreciated.

you can not directly use int[] return type. it's managed dll returned not.

change return type "intptr" receive pointer.

[dllimport("modbot_model_win64.dll", charset = charset.unicode)] public static extern intptr mpc(double x, double y, double theta, double vx, double vy, double vtheta); 

then use marshall copy data

intptr ints = mpc(0, 0, 0, 0, 0, 0); int ret[] = new int[n]; //n number of elements marshall.copy(ints, ret, 0, n); 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -