>> > Does anybody know how to fix this issue. Or is there any other good
>> > practice passing strings from unmanaged libs tto managed libs?
[quoted text clipped - 27 lines]
> Can you point me to pretty good practices of passing strings of
> individual length's from unmanaged code to C++/CLI code?
First up, you must compile all code using the unmanaged DLL's classes
without /clr and with the same compiler version used by the DLL. Otherwise
the ODR is violated. This is not a recommendation, it is an absolute
requirement to get any sort of reasonable behavior.
Next, you should use fundamental types such as wchar_t* or char* to pass
data between those files compiled without /clr and the ones compiled with.
The definition of those types aren't changed by /clr or the compiler
version. These convert to and from the std::string and CString variants in
the usual way.
Then, use the following functions to get the data to/from .NET
System::String:
PtrToStringChars
System::Runtime::InteropServices::Marshal::PtrToString{Ansi|Auto|BSTR|Uni}
If you do that, everything should link and run without problems. If the DLL
was compiled using an earlier version of the compiler, then the static lib
wrappers described in "First up" should use extern "C" functions. You
should probably do that anyway.
> Thanks again,
>
> Sebastian Dau
sebastian.dau@googlemail.com - 04 Jun 2007 15:56 GMT
> >> > Does anybody know how to fix this issue. Or is there any other good
> >> > practice passing strings from unmanaged libs tto managed libs?
[quoted text clipped - 53 lines]
>
> > Sebastian Dau
Thanks, Ben I'll give that a try and see how it works.