C++/CLI std::wstring behaving VERY strangely in release build

Started by
13 comments, last by Raeldor 17 years, 5 months ago
Hi All, This works fine in debug mode, but in release mode I am getting errors thrown when passing std::wstring from managed to un-managed. I narrowed it down to one line...

		std::wstring name2=L"test";

which in the debugger in debug build says {"test"}, but in release mode it says {"st"}. Something very strange is going on here. Can anyone shed some light? Thanks Rael
Advertisement
To add to this, when I try and call my unmanaged function with...
		m_node=new NW::Node(L"test");

it works fine in debug mode, but in release mode it blows up with unknown software exception.
Here's another interesting tidbit. If I change from Multithreaded DLL to Multithreaded debug dll in the c++ code generation options, it works. If I change back... it stops working again.
Well, the problem could lay in L##quote (the macro used to change from wide to ansi strings).

I guess to help further, we'd need more info... =[ what are the errors exactly?
C++/CLI was a terrible idea to begin with, and Microsoft seems to agree. Death of the monstrosity is imminent. Please migrate any source code you might have using it to something else before it's too late.
Quote:Original post by Anonymous Poster
C++/CLI was a terrible idea to begin with, and Microsoft seems to agree. Death of the monstrosity is imminent. Please migrate any source code you might have using it to something else before it's too late.


Don't be a retard.
Quote:Original post by MENTAL
Quote:Original post by Anonymous Poster
C++/CLI was a terrible idea to begin with, and Microsoft seems to agree. Death of the monstrosity is imminent. Please migrate any source code you might have using it to something else before it's too late.


Don't be a retard.


You think writing new code for C++/CLI sounds like a good idea?
Let's not kid ourselves. C++/CLI is a combination of the worst parts of C++ and the worst parts of .NET. If this isn't the worst programming environment ever created already, add some special syntax to make the already complex C++ syntax even worse, and you sure are pretty close to it.

We all know, and Microsoft also knows, that it was intended entirely as a stop gap measure to get people to quickly move their existing C++ code to .NET. But the idea is that after that is done, you can move it piece by piece to a real .NET language later.

Writing new code in it is just wrong.
i don't even want to comment on the stuff the previous anon said..

but Raeldor, it seems to me that your problem is something simple like not having defined UNICODE in release mode or something like that.
If it works in debug and doesn't in release and is related to the 'L' string prefix its likely to be the fault of some configuration problems.
Quote:Original post by Raeldor
Hi All,

This works fine in debug mode, but in release mode I am getting errors thrown when passing std::wstring from managed to un-managed. I narrowed it down to one line...
*** Source Snippet Removed ***
which in the debugger in debug build says {"test"}, but in release mode it says {"st"}. Something very strange is going on here. Can anyone shed some light?

Thanks
Rael

You can't rely on the debugger to look the variable state in release mode - optimization destroys much of the meaning of the values you get.

Concerning your bug, I'd say that the bug is also present in debug, but that it is probably hidden by some other thing (such as pre-initialized memory buffers and so on). Run your code through a bound-checker like tool, you'll likely find some other problems.

@Anonymous Poster: if writing new code in C++/CLI is a Bad Idea, how do you migrate the code you wrote in unmanaged C++ to your managed code base? You discard it and rewrite it in C#, trying to keep your customer happy while you are wasting his money?

This topic is closed to new replies.

Advertisement