P/Invoke Interop Problem
hi all,
i've been working on program control special type of scientific camera! i'm trying use camera's sdk written in unmanaged c++, , i'm trying interoperate sdk using c#.
everything going till got work function had char* arguments, unmanaged method signature is:
int flilistfirst(int *domain, char *filename, size_t fnlen, char *name, size_t namelen);
i first tried use following managed signature:
[dllimportattribute(@strpath, entrypoint = "flilistfirst", callingconvention = callingconvention.stdcall)]
public static extern int flilistfirst(out int domain, out intptr filename, [system.runtime.interopservices.marshalasattribute(system.runtime.interopservices.unmanagedtype.u4)] uint fnlen, out intptr name, [system.runtime.interopservices.marshalasattribute(system.runtime.interopservices.unmanagedtype.u4)] uint namelen);
when marshalled returned intptrs string using marshal.ptrtostringauto() converted string looked strange, intptr pointing wrong address.
i tried change intptrs stringbuilder, result stackoverflowexception! current managed signature i'm trying worked is:
[dllimportattribute(@strpath, entrypoint = "flilistfirst", callingconvention = system.runtime.interopservices.callingconvention.stdcall)]
public static extern int flilistfirst(out int domain, [marshalas(unmanagedtype.lpwstr)] out stringbuilder filename, [system.runtime.interopservices.marshalasattribute(unmanagedtype.u4)] uint fnlen, [marshalas(unmanagedtype.lpwstr)] out stringbuilder name, [system.runtime.interopservices.marshalasattribute(unmanagedtype.u4)] uint namelen);
i should mention tried pair stringbuilders whith lpstr too, once didn't pair them unmanaged type @ all, in cases got exception!
since i'm new p/invoke, seems can't figure out going wrong!
i appreciate help, friends!
ok, problem solved, removed out keyword before stringbuilder definitions, , it's working!
.NET Framework > Common Language Runtime Internals and Architecture
Comments
Post a Comment