Having trouble with using C++ library in C# -
so i'm writing program uses 3rd party dll written in c++. i'd write program in c#, since know thing or 2 language , never did in c++.
got library called ciusblib in pack of files: .dll, .h, .lib, .ext. program meant target computer (win7 32bit), different i'm developing on (win10 , win8 both 64bit) - have limited access target computer. i'm using visual studio 2015 , according vs's object browser dll contains classes several methods want use.
found there 3 methods available - reference library in c# project, p/invoke (using dllimport) , c++/cli wrapper.
so first tried referencing library in c# project, directly crashes on instantiating class on both dev computers , throws accessviolationexception on target computer. wasn't able figure out why it's happening blamed on library's code being unmanaged.
after doing research found dllimport can't used on methods closed in class. tried c++/cli wrapper, realized referencing c++ library in visual c++ clr project adds "interop.ciusblib.1.0.dll" library references, apparently managed. at
namespace ciusblib_wrap { public ref class ciusblib_wrapper { chostdrv* wrap_class; public: ciusblib_wrapper() { wrap_class = new chostdrv}; }; }
visual studio shows error on asterisk, saying class c++/cli. i'm trying wrap wrapped library. vs automatically create implicit wrapper, preventing me writing own?
after tried noticed library contents different when viewed in vs's object browser in clr project: dll in clr project , when viewed in c# project: dll in c# project. in first picture, chostdrv , ihostdrv interface classes , chostdrvclass ref class; in other picture, chostdrv interface , chostdrv class. don't understand, why different?
so see 2 ways find solution:
- find out why instantiating library's class throws accessviolationexception on target computer , crashes program on other computers
- create wrapper ciusblib.dll , not interop.ciusblib.1.0.dll
- something else?
any welcome here, because if don't find solution i'll have write program in c++ , sucks me.
Comments
Post a Comment