Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Shelf | Store

Privacy Policy


Post Reply 
Declaration of swprintf for MinGW users.
Author Message
someone972 Offline
Junior Member

Posts: 15
Joined: May 2012
Reputation: 0
Post: #1
Declaration of swprintf for MinGW users.
In case anyone decides to use MinGW to compile HPL1/OALWrapper, you may have found that the version of swprintf provided with MinGW takes three arguments, omitting the size of the buffer. The four argument function exists in MinGW, but it is under a different name. To remedy this I created the following header:
PHP Code: (Select All)
#ifndef MINGW_FUNCTION_DECL_H
#define MINGW_FUNCTION_DECL_H

#ifdef __MINGW32__
#include <cstring>
#include <cstdarg>
#include <cwchar>

inline int swprintf(wchar_t *bufsize_t length, const wchar_t *fmt, ...)
{
    
va_list args;
    
int i;

    
va_start(argsfmt);
    
i=_vsnwprintf(buf,length,fmt,args);
    
va_end(args);
    return 
i;
};

inline int vswprintf(wchar_t *bufsize_t length, const wchar_t *fmtva_list args)
{
    return 
_vsnwprintf(buf,length,fmt,args);
}

#endif //__MINGW32__
#endif //MINGW_FUNCTION_DECL_H 
Then anywhere that the functions are used, I add the following to the header file:
PHP Code: (Select All)
#ifdef __MINGW32__
    #include "../MinGW_function_declarations.hpp" //May be a different path depending on project.
#endif 

Feel free to provide feedback or criticisms of my method. Hopefully this will be of use to anyone using MinGW.
05-11-2012 02:09 AM
Find all posts by this user Quote this message in a reply
Urkle Offline
FG - Associate

Posts: 1,101
Joined: Jul 2006
Reputation: 14
Post: #2
RE: Declaration of swprintf for MinGW users.
A better way maybe to rework that code to simply use a wstring.. wchar stuff is such a PITA.

Developing away on one of
Mac Pro Dual 2Ghz, 7GB RAM, Snow Leopard, nVidia 8800 512MB.
Linux, 3-core AMD, 4GB RAM, Fedora 16, nVidia 450 1GB
05-11-2012 02:22 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)