c++ cli - Calling c++ generic method from C# -
i created c++ 64-bit library follows
// unmanagedcli.h #pragma once using namespace system; using namespace system::runtime::interopservices; namespace unmanagedcli { [dllimport("msvcrt.dll", entrypoint = "memset", callingconvention = callingconvention::cdecl, setlasterror = false)] extern intptr memset(intptr dest, int c, int count); //[system::runtime::compilerservices::extensionattribute] public ref class unmanaged sealed { public: static void free(void* unmanagedpointer) { marshal::freehglobal(intptr(unmanagedpointer)); } generic <typename t> t : value class static intptr new(int elementcount) { return marshal::allochglobal(sizeof(t) * elementcount); } generic <typename t> t : value class static intptr newandinit(int elementcount) { int sizeinbytes = sizeof(t) * elementcount; intptr newarrayptr = marshal::allochglobal(sizeinbytes); memset(newarrayptr, 0 , sizeinbytes); return newarrayptr; } generic <typename t> t : value class static void* resize(void* oldpointer, int newelementcount) { return marshal::reallochglobal(intptr(oldpointer), intptr((int) sizeof(t) * newelementcount)).topointer(); } }; }
from c# include reference, check unsafe code in build, , in main this:
using unmanagedcli; unsafe class testwriter { static void main() { unmanaged un; //i can't access of c++ methods in here? } }
when un.
don't see of methods in c++/cli library? builds , runs fine, cannot access c++ @ all.
all methods of c+++/cli class (unmanaged) static. try using unmanaged.method syntax in c# (you don't have create object).
Comments
Post a Comment