Skip to main content
GameDev.net gamedev.net
🔒 Locked

mingw-g++ and strsafe.h

Started by yckx Jun 17, 2006 at 10:00 AM 3 replies 6k views
Original Post
yckx
yckx
I tried to compile after including strsafe.h and got error after error of "expected primary-expression before ',' token." After tooling around a bit, I found that mingw-g++ is choking on all the NULLs in strsafe.h. Does anybody know how a fix or workaround for this?
Enigma
Enigma
Since strsafe.h is "Safer String Handling in C" and g++ is a C++ compiler, why exactly are you wanting to use the former in the latter? C++ already has perfectly safe string handling via the std::string class.

If you are in one of the ~0.1% of situations where using strsafe.h makes sense, presumably you just need to ensure that NULL is defined, so include before strsafe.h.

Σnigma
yckx
yckx
Quote:
Original post by Enigma
why exactly are you wanting to use the former in the latter?

Because it has been my experience that Win32 functions that take LPTSTR (and similar) paramaters don't always play well with std::strings.

I'd be happy to learn of a good alternative (other than MFC).

Oh, and it's been nearly a year since I've even looked at code, so I'd forgotten about cstddef. Thanks for the reminder.
Enigma
Enigma
Any time you need to pass a string to a Win32 function you should be able to use a std::basic_string< TCHAR > by calling the c_str() member function. Any time you need to pass a buffer to a Win32 function for the function to fill you should be able to use a std::vector< TCHAR >. I'm not aware of any Win32 function where neither of those two techniques works and they are both superior to manual memory management.

Σnigma
yckx
yckx
Quote:
Original post by Enigma
Any time you need to pass a buffer to a Win32 function for the function to fill you should be able to use a std::vector< TCHAR >.

Ah, that's the trick I needed. Much thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.