Problems selecting correct override
-
I'm having a strange problem that I'm hoping someone can shed some light on. In my COM server (.exe) i invoke the CString method Format. The problem is execution goes to the wrong override! Then it blows up. Here is the initial command: [ccode] strDiag.Format(("iTotalUnused * 100) / g_ThreadsArray.GetSize() = %d",iTotalUnused * 100) / g_ThreadsArray.GetSize()); [/ccode] When this executes I trace it into: [ccode] void AFX_CDECL CString::Format(UINT nFormatID, ...){ CString strFormat; VERIFY(strFormat.LoadString(nFormatID) != 0); va_list argList; va_start(argList, nFormatID); FormatV(strFormat, argList); va_end(argList);} [/ccode] instead of [ccode] // formatting (using FormatMessage style formatting)void AFX_CDECL CString::FormatMessage(LPCTSTR lpszFormat, ...){ [/ccode] The actual blowup occurs in the LoadString function (which I don't want called in the first place0. It calls AfxGetResourceHandle which asserts afxCurrentResourceHandle is NULL. I don't believe this is a bug in the CString class (i've used it too many times in this program.) I don't see anything wrong in my code, unless its environmental: This control is windowless, it launches some number of worker threads and assigns tasks to them as requested. This code runs in one of the worker threads. The threads are created by instantiating a CWinThread derived object and invoiking its CreateThread method. Thanks for the help, Bill
-
I'm having a strange problem that I'm hoping someone can shed some light on. In my COM server (.exe) i invoke the CString method Format. The problem is execution goes to the wrong override! Then it blows up. Here is the initial command: [ccode] strDiag.Format(("iTotalUnused * 100) / g_ThreadsArray.GetSize() = %d",iTotalUnused * 100) / g_ThreadsArray.GetSize()); [/ccode] When this executes I trace it into: [ccode] void AFX_CDECL CString::Format(UINT nFormatID, ...){ CString strFormat; VERIFY(strFormat.LoadString(nFormatID) != 0); va_list argList; va_start(argList, nFormatID); FormatV(strFormat, argList); va_end(argList);} [/ccode] instead of [ccode] // formatting (using FormatMessage style formatting)void AFX_CDECL CString::FormatMessage(LPCTSTR lpszFormat, ...){ [/ccode] The actual blowup occurs in the LoadString function (which I don't want called in the first place0. It calls AfxGetResourceHandle which asserts afxCurrentResourceHandle is NULL. I don't believe this is a bug in the CString class (i've used it too many times in this program.) I don't see anything wrong in my code, unless its environmental: This control is windowless, it launches some number of worker threads and assigns tasks to them as requested. This code runs in one of the worker threads. The threads are created by instantiating a CWinThread derived object and invoiking its CreateThread method. Thanks for the help, Bill
The problem was caused by a typo,the parentheses are off. Thanks for the help, Bill
-
I'm having a strange problem that I'm hoping someone can shed some light on. In my COM server (.exe) i invoke the CString method Format. The problem is execution goes to the wrong override! Then it blows up. Here is the initial command: [ccode] strDiag.Format(("iTotalUnused * 100) / g_ThreadsArray.GetSize() = %d",iTotalUnused * 100) / g_ThreadsArray.GetSize()); [/ccode] When this executes I trace it into: [ccode] void AFX_CDECL CString::Format(UINT nFormatID, ...){ CString strFormat; VERIFY(strFormat.LoadString(nFormatID) != 0); va_list argList; va_start(argList, nFormatID); FormatV(strFormat, argList); va_end(argList);} [/ccode] instead of [ccode] // formatting (using FormatMessage style formatting)void AFX_CDECL CString::FormatMessage(LPCTSTR lpszFormat, ...){ [/ccode] The actual blowup occurs in the LoadString function (which I don't want called in the first place0. It calls AfxGetResourceHandle which asserts afxCurrentResourceHandle is NULL. I don't believe this is a bug in the CString class (i've used it too many times in this program.) I don't see anything wrong in my code, unless its environmental: This control is windowless, it launches some number of worker threads and assigns tasks to them as requested. This code runs in one of the worker threads. The threads are created by instantiating a CWinThread derived object and invoiking its CreateThread method. Thanks for the help, Bill
Seems like the evil comma operator strikes back :) Well I guess all the problem reduces to having your first quotation mark displaced to the right of the second parenthesis, instead than to the left. As it stands, your expression evaluates as follows:
strDiag.Format(
(
"iTotalUnused * 100) / g_ThreadsArray.GetSize() = %d",
iTotalUnused * 100
) / g_ThreadsArray.GetSize());==> (
operator ,
evaluates to its second argument)strDiag.Format(
(
iTotalUnused * 100
) / g_ThreadsArray.GetSize());==>
strDiag.Format(iTotalUnused * 100 / g_ThreadsArray.GetSize());
and this of course selects the
Format(UINT,...)
overload. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo