Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

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

This topic is 4289 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Guest 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!