How to call a C dll generated by R CMD SHLIB, from C#? -
i call method in dll code written in c c # code can't that. error message is:
unhandled exception: system.badimageformatexception: attempt made load program incorrect format. (exception hresult: 0x8007000b) @ displaymessagedll.program.dividetwo(int32 a, int32 b, int32* res) @ displaymessagedll.program.main(string[] args) in c:\users\mat\documents\visual studio 2013\projects\displaymessagefromdll\consoleapplication1\program.cs:line 30 press key continue . . .
in fact, dll generated following command line in windows console: r cmd shlib --preclean simple.c
code of simple.c class is:
void dividetwo(int a, int b, int *result) { *result = a/b; } void rdividetwo(int *a, int *b, int *result) { dividetwo(*a, *b, result); }
and c# code calls dividetwo() method :
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.runtime.interopservices; using rdotnet; using rdotnet.nativelibrary; using rdotnet.utilities; using rdotnet.internals; using rdotnet.dynamic; using rdotnet.diagnostics; using rdotnet.devices; namespace displaymessagedll { class program { [dllimport("c:/rdoc/simple.dll", callingconvention = callingconvention.cdecl, charset = charset.unicode)] unsafe public static extern void dividetwo(int a, int b, int* res); // dll support unsafe static void main(string[] args) { int = 25, b = 25; int res = 0; dividetwo(a, b, &res); console.writeline("result of " +a+ " / " +b+ " = " + res); console.read(); } } }
why isn't dll generated command 'r cmd shlib simple.c' accessible c# code? whereas if generate dll in visual studio 2013 same code, dll accessible c # code.
Comments
Post a Comment