Passing a char* argument to a C++ DLL function from a C# app -


i trying use dll function declared void process(char* data) c#.

the dll provides various functions operate oculusrift. function supposed display in oculus data image , used functioning app.

in code, generate byte[] bitmap image, convert other things (char[], append stringbuilder,...) aiming @ passing process function.

i load process function dll via loadlibrary (to load dll) + getprocadress (to access function). can't use dllimport because want close possible way interface of other app (written in c++) works dll.

i tried using
[unmanagedfunctionpointer(callingconvention.cdecl)] private delegate void process([marshalas(unmanagedtype.lpstr)]stringbuilder data);

or
[unmanagedfunctionpointer(callingconvention.cdecl)] private delegate void process(stringbuilder data);

(i read passing string/stringbuilder trick because it's marshaled default char*). result had full string passed argument dll , not char*.

i tried pass intptr argument too, using marshal copy ,

[unmanagedfunctionpointer(callingconvention.cdecl)] private delegate void process(intptr data);.
result had memory access violation exception.

i tried various things using unsafe code such implementing whole data creation process other app (for purposes need simplified version) or creating data want in char[] , copying char[] char* passed

[unmanagedfunctionpointer(callingconvention.cdecl)] private unsafe delegate void process(char* data);

this resulted in stack overflow exceptions stackalloc , in memory access violation exception.

at point, think i'm missing , need help. don't know if there kind of lock causing memory exception error (i made sure image of right size), don't know if i've not misunderstood marshaling process, etc.

i hope i've been explicit enough concerning problem.

in c char used represent bytes because in c type byte doesn't exists. or equal char type.

so map c#:

[unmanagedfunctionpointer(callingconvention.cdecl)] private delegate void process([marshalas(unmanagedtype.lparray)]byte[] data); 

or

[unmanagedfunctionpointer(callingconvention.cdecl)] private delegate void process(byte[] data); 

regards


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -