wchar_t NUL in managed/unmanaged C++
I need to use this (unmanaged) C++ library. One of the methods has a wchar_t* as a parameter. Tried using it in C#, but all my attempts resulted in an error code 'invalid argument'.
I wrote a managed C++ wrapper for it - same problem. Now I compared the values of arguments from my C++ wrapper and native C++ example that came with the library. The only significant difference I see is that NUL in my managed C++ is "0 L''" (Visual Studio watch) and NUL in unmanaged examp开发者_如何学运维le is simply "0". They both have the same value... 0.
Can this really be the issue? (I tried manually setting that character to '0' but got the same results) If yes, how do I solve it?
EDIT: Image: http://img6.imageshack.us/img6/5977/comparisonofvalues.png Ok, on the left side is my code (managed C++), on the right side is the example (unmanaged C++). As it is, right one is working, left one isn't (the function rejects the arguments). I think the issue is in the 17th character - NUL. Any further thoughts?
The difference in your debugger is just appearances. You'll note that the debugger generally shows two values: the binary value, and the matching Unicode character. But you can't show a Unicode character for binary value 0. The two debuggers deal with it in slightly different ways (showing L''
versus showing nothing) , but the bits in memory are the same.
On the other hand, your ip
string is garbage.
You might check your project properties. There is a compiler option that controls whether wchar_t is treated as a built-in type or not. Setting this to NO will use the old header definition of wchar_t and may fix your problem.
精彩评论