Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problems selecting correct override

Problems selecting correct override

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomsysadmindebugging
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bill Wilson
    wrote on last edited by
    #1

    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

    B J 2 Replies Last reply
    0
    • B Bill Wilson

      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

      B Offline
      B Offline
      Bill Wilson
      wrote on last edited by
      #2

      The problem was caused by a typo,the parentheses are off. Thanks for the help, Bill

      1 Reply Last reply
      0
      • B Bill Wilson

        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

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups