Importing C++ custom library functions into C# -


i have large c++ library need incorporate c# project. successful in using dllimport access functions library, this:

[dllimport("mylib.dll")] public static extern int samplefunction(string param); 

however, can't seem figure out how make work functions either have parameter or return type not defined within dll (i.e., code in dll imports file), such example function takes in list:

[dllimport("mylib.dll")] public static extern std::vector<myclass> myfunction(string param); 

for std library functions, know can dll , import in, other classes myclass in above example? need create managed wrapper class in c++ each of these classes, or there way this?

std::vector<myclass>, or indeed unmanaged c++ class, cannot used interop c#. indeed, if wished consume function unmanaged c++ module you'd have make sure using same compiler , dynamic runtime dll exported function.

you'll need find other way implement functionality. there lots of different ways that.

  • you expose p/invoke interface functionality. involve declaring struct represent data of class, , serializing , struct.
  • you might consider com interface won't offer great advantages on p/invoke. you'd still need serialize class.
  • a c++/cli wrapper yet option. you'd wrap unmanaged class managed c++/cli class, , consume c#.

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -