c++ - How to use C# textbox inputs with C structs and imports -
i have library (*.dll
file) written in c. trying use windows form
application building. have redefined struct needed import work. how can assign values variables in struct.
[dllimport("hdnpic.dll")] public static extern int hidden(hid4cinp hid4cinp); [structlayout(layoutkind.sequential)] public struct hid4cinp { public const int maxsize = 500; public double alpha_c; public double alpha_m; public double alpha_y; public double alpha_k; public double freq; public double dsmp; public double cdxy; public double cdhi_c; public double cdhi_m; public double cdhi_y; public double cdhi_k; public double amp1; public double perd; public int funtype; public int smooth; public int inpres; public int width; public int height; }
i have written code in c#. can suggest me how assign values hid4cinp struct variables.
try following :
using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.interopservices; namespace consoleapplication73 { class program { [dllimport("hdnpic.dll")] public static extern int hidden(intptr hid4cinp); [structlayout(layoutkind.sequential)] public struct hid4cinp { public const int maxsize = 500; public double alpha_c; public double alpha_m; public double alpha_y; public double alpha_k; public double freq; public double dsmp; public double cdxy; public double cdhi_c; public double cdhi_m; public double cdhi_y; public double cdhi_k; public double amp1; public double perd; public int funtype; public int smooth; public int inpres; public int width; public int height; } static void main(string[] args) { hid4cinp hid4cinp = new hid4cinp(); hid4cinp.alpha_c = 123; intptr hid3cinpptr = marshal.allochglobal(marshal.sizeof(hid4cinp)); marshal.structuretoptr(hid4cinp, hid3cinpptr, true); int results = hidden(hid3cinpptr); } } }
Comments
Post a Comment