Get byte[] in C# from char* in C++ -
in c# have data type byte[]
, want fill in using c++ function returns char*
the c++ function (in imagedata.dll
)
char* pmemorybuffer = null; char* loaddata(const char *filename) { // processing pmemorybuffer ... return pmemorybuffer; }
import native dll c#:
[dllimport(".\\modules_native\\imagedata.dll", entrypoint = "loaddata")] private extern static byte[] loaddata(string filename);
the byte[]
data in c#
byte[] buffer = new byte[256*256]; buffer = loaddata("d:\\mypic.tif");
apparently not working yet, presents idea of want do. wondering how make work, , right way it. education.
try this
// c++ void loaddata(unsigned char* *pmemorybuffer, const char *filename) { // processing pmemorybuffer ... *pmemorybuffer = resutss; }
import native dll c#:
[dllimport(".\\modules_native\\imagedata.dll", entrypoint = "loaddata")] private extern static void loaddata(out intptr data, string filename);
when function returns data point array , can read contents using marshal class. guess copy new byte array.
byte[] buffer = new byte[256*256]; buffer = marshal.copy(loaddata(buffer ,"d:\\mypic.tif"), buffer , 0, buffer.length);
Comments
Post a Comment