c# - how to create a c++\cli wrapper for unmanaged c dll -
i'm confusing myself haven't done before , bit of direction helpful.
trying call c
code c#
application. have tried using pinvoke
finding bit tricky. thought try doing c++\cli
wrapper.
there complicated structs have double arrays of variable length hard handle pinvoke
.
i've read bit on how done can't figure out. of i've found relates wrapping c++
instead of c
. c
code exporting functions works java application , jna
service. have c
code, headers, library , dll rather not make changes existing not upset other consuming applications. c#
application calling 64 bit, examples creating win32 libraries, matter?
update: adding code below:
note: 1 function of several , simplest 1 similar.
c header: typedef struct mystruct_t { double prefix[8]; int length; double array[1]; } mystruct; c: extern "c" __declspec( dllexport ) mystruct *dosomething(const mystruct *input, double a) { mystruct *output; //dosomething return output; }
there's little difference between wrapping c , c++. need make c++/cli class library. write functions in managed c++ ref class wrap native code.
for instance, suppose dll exports function:
int sqr(int x)
then in class library include header file:
#include <mynativelibrary.h>
you need supply import library linker.
then can expose function. simplest way wrap functions static methods of ref class. instance:
public ref class class1 { public: static int sqr(int x) { return ::sqr(x); } };
you can consume assembly in c# code other assembly.
Comments
Post a Comment