I've recently implemented a string class called
GString, adapting some WFC code in order to replace MFC CString. Now the problem is, if I try to use the Format method, whenever a GString is part of the argument list, the corresponding %s will become "(null)" in the resulting string.
CString tempm;
GString tempg;
CString test_mfc=_T("test mfc");
GString test_glib=_T("test glib");
tempm.Format(_T("%s\\%s"),test_mfc,test_glib); // becomes "test mfc\(null)"
tempg.Format(_T("%s\\%s"),test_mfc,test_glib); // same as aboveAs you can see, CString::Format() and GString::Format() produce the same string in the end, which makes me assume it's an argument problem, rather than my Format being broken, but I'm not 100% sure. My question is, how do I make it work the same way as CString? By using the GString::GetBuffer() method it works just fine and there's no (null) error, but I want it to behave as close as possible to CString, so that's not really a solution. I'm not even sure what operator is called when the arguments are passed to va_list, and the debugger in VS isn't helping at all.
This is my format method, just in case:
void GString::Format(LPCTSTR pszFormat, ...)
{
va_list args;
int len;
TCHAR* buffer;
va_start(args,pszFormat);
len=_vsctprintf(pszFormat,args)+1;
buffer=(TCHAR*)malloc(len*sizeof(TCHAR));
_vstprintf(buffer,pszFormat,args);
m_String=buffer;
free(buffer);
}Thanks!