C# using my own C++/CLI DLL: Error: 'mytrainOp' is not supported by the language -
my c++ class has 1 method:
string mythreadscpp::mythreadscppclass::train(){ double sum = 0.0; long max = 100 * 1000; int perc = 0;; (long n = 0; n < max; n++){ sum += 4.0*pow(-1.0, n) / (2 * n + 1.0); int rem = n % (max/10); if (rem == 0){ perc = 100 * n / max; cout << perc << "%" << endl; } } cout << "100%" << endl; ostringstream oss; oss << "result = " << sum; return oss.str(); }
it works fine.
c++/cli class library has 1 method:
string threadscppwrapper::threadscppwrapperclass::mytrainop(int% i){ i++; return ptr->train(); }
it builds fine.
c# code consuming dll:
namespace threadscsharp { public partial class frmmain : form { private void btntrain_click(object sender, eventargs e) { threadscppwrapperclass obj = new threadscppwrapperclass(); int = 5; obj.mytrainop(i); /* error */ } } }
intellisense errors above line: error 1 no overload method 'mytrainop' takes 1 arguments error 2
pointers , fixed size buffers may used in unsafe context
experts, please help.
it not great error message, c# compiler struggles mightily when trying figure out std::string
object return. hidden in c# program since don't use it. doesn't matter, compiler still needs deal it.
you must return managed string instead, this:
string^ threadscppwrapper::threadscppwrapperclass::mytrainop(int% i){ i++; return gcnew string(ptr->train().c_cstr()); }
and of course if don't have use string declare return value type void
. next error 1 reminds pass argument ref
, can figure 1 out.
Comments
Post a Comment