MFC application crash

Discussion in 'C++' started by Sandy, Jan 24, 2007.

  1. Sandy

    Sandy Guest

    HI All,
    I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof
    service pack 2 and it works properly on my machine, but when I run the
    same exe on a different machine (Windows XP Prof SP-2), The application

    is bought up and after some time its throwing a windows xp error dialog

    box saying,

    I am also running the same application on 2 more machines there
    everything works fine.

    Here is thr Windows XP error dialog box that appreas when its crashed
    TODO: <File description> has encountered a problem and needs to close.
    We are sorry for any inconenience.

    If you are in the middle of something, the information you were working

    on might be lost.


    Please tell Microsoft about this problem.


    blab blah....


    I have function called OnNotifyNewData (WPARAM wParam, LPARAM lParam)
    which appreas to be cauing the problem. When I run the application
    commenting this function its didnt crashed.

    LRESULT CUserViewFrame::OnNotifyNewData (WPARAM wParam, LPARAM lParam)
    {
    const char* strVariable("CUserViewFrame::OnNotifyNewData START");
    const char* strValue("6");
    CUtility::LogDebugInfo( strVariable, strValue);

    WRITE_LOG_FUNCTION_ENTRY("LRESULT CUserViewFrame::OnNotifyNewData
    (WPARAM wParam, LPARAM lParam)")

    PInstData pInstData = (PInstData)wParam;
    if (!pInstData) return 0;

    CString csText;
    char buffer[255];
    LVFINDINFO info;
    int iIndex = 0;

    PSystemSetting pSystemSetting = CSystemSetting::GetObject();

    info.flags = LVFI_WRAP|LVFI_STRING;
    std::vector<CMarketData>::const_iterator iter;
    std::vector<CParticipant>::const_iterator iterpart;

    const std::vector<CMarketData> & userListBid =
    pInstData->GetMarketDataBid();
    for (iter = userListBid.begin(); iter != userListBid.end(); iter++)
    {
    const std::vector<CParticipant> & participants =
    iter->GetParticipants();
    for (iterpart = participants.begin(); iterpart != participants.end();
    iterpart++)
    {
    if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
    {
    memset(&buffer, 0, sizeof(buffer));
    if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
    continue;
    //sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
    info.psz = iterpart->GetUserName();
    iIndex = m_ctrlUserListCtrl.FindItem(&info);
    if (iIndex == -1)
    { // insert the item
    iIndex = m_ctrlUserListCtrl.GetItemCount();

    if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
    continue;
    //csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()
    csText = iterpart->GetUserName(); //Sanjeev 012407
    int size = iterpart->GetUserName().GetLength();
    char bufsize[20];
    memset(&bufsize, 0, sizeof(bufsize));
    _itoa(size,bufsize,10);
    CUtility::LogDebugInfo( "OnNotifyNewData - BID UserName", bufsize);
    m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
    0, LVIS_SELECTED, 0, 0);
    char * pchText = new char [csText.GetLength() + 1];
    strcpy(pchText, (LPCTSTR)csText);
    m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
    }
    if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
    continue;
    //csText.Format(TEXT("%s"),
    pInstData->GetInstName()/*.c_str()*/); csText =
    pInstData->GetInstName();
    m_ctrlUserListCtrl.SetItemText(iIndex,
    eUserViewListColumn::BID_INST, csText);

    memset(&buffer, 0, sizeof(buffer));
    sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
    csText.Format(buffer, iterpart->GetSize());
    m_ctrlUserListCtrl.SetItemText(iIndex,
    eUserViewListColumn::BID_SIZE, csText);

    memset(&buffer, 0, sizeof(buffer));
    sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
    csText.Format(buffer, iter->GetPrice());
    m_ctrlUserListCtrl.SetItemText(iIndex,

    eUserViewListColumn::BID_PRICE, csText);

    if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
    continue;
    csText.Format("%s", iterpart->GetTimestamp().c_str());
    m_ctrlUserListCtrl.SetItemText(iIndex,
    eUserViewListColumn::BID_TIME, csText);
    }
    }
    }

    const std::vector<CMarketData> & userListAsk =
    pInstData->GetMarketDataAsk();
    for (iter = userListAsk.begin(); iter != userListAsk.end(); iter++)
    {
    const std::vector<CParticipant> & participants =
    iter->GetParticipants();
    for (iterpart = participants.begin(); iterpart != participants.end();
    iterpart++)
    {
    if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
    {
    memset(&buffer, 0, sizeof(buffer));
    if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
    continue;
    //sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
    int size = iterpart->GetUserName().GetLength();
    char bufsize[20];
    memset(&bufsize, 0, sizeof(bufsize));
    _itoa(size,bufsize,10);
    CUtility::LogDebugInfo( "OnNotifyNewData - ASK UserName", bufsize);
    info.psz = iterpart->GetUserName();
    iIndex = m_ctrlUserListCtrl.FindItem(&info);
    if (iIndex == -1)
    { // insert the item
    iIndex = m_ctrlUserListCtrl.GetItemCount();
    if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
    continue;
    //csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()*/);
    csText = iterpart->GetUserName();
    m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
    0, LVIS_SELECTED, 0, 0);
    char * pchText = new char [csText.GetLength() + 1];
    strcpy(pchText, (LPCTSTR)csText);
    m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
    }
    if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
    continue;
    //csText.Format(TEXT("%s"), pInstData->GetInstName().c_str());
    csText = pInstData->GetInstName();
    m_ctrlUserListCtrl.SetItemText(iIndex,

    eUserViewListColumn::ASK_INST, csText);

    memset(&buffer, 0, sizeof(buffer));
    sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
    csText.Format(buffer, iterpart->GetSize());
    m_ctrlUserListCtrl.SetItemText(iIndex,

    eUserViewListColumn::ASK_SIZE, csText);

    memset(&buffer, 0, sizeof(buffer));
    sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
    csText.Format(buffer, iter->GetPrice());
    m_ctrlUserListCtrl.SetItemText(iIndex,

    eUserViewListColumn::ASK_PRICE, csText);

    if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
    continue;
    csText.Format("%s", iterpart->GetTimestamp().c_str());
    m_ctrlUserListCtrl.SetItemText(iIndex,

    eUserViewListColumn::ASK_TIME, csText);
    }
    }
    }

    VERIFY(m_ctrlUserListCtrl.SortItems( CompareFunction, r

    einterpret_cast<DWORD>(&m_ctrlUserListCtrl)));

    WRITE_LOG_FUNCTION_EXIT("LRESULT
    CUserViewFrame::OnNotifyNewData (WPARAM wParam,
    PARAM
    lParam)")

    const char* strVariable1("CUserViewFrame::OnNotifyNewData END");
    CUtility::LogDebugInfo( strVariable1, strValue);

    return 0;
    }


    Is there any chance the sprintf or CString Format function is creating
    this problem.

    I have spent lot of time it undertsanding this bug with no success. Any
    help would be greatly appreciated.

    Regards,
    Sandy
     
    Sandy, Jan 24, 2007
    #1
    1. Advertising

  2. Sandy

    Ian Collins Guest

    Sandy wrote:
    > HI All,


    Please stop posing the same off topic question over and over again.

    --
    Ian Collins.
     
    Ian Collins, Jan 24, 2007
    #2
    1. Advertising

  3. Sandy

    Sourcerer Guest

    "Sandy" <> wrote in message
    news:...
    <snip>

    Hmm, if you write programs as you post requests for help, it's no wonder your
    programs crash.

    Try asking your question on:
    microsoft.public.dotnet.languages.vc

    This group is for standard C++ only.

    --
    "It is easy in the world to live after the world's opinion; it easy in solitude
    to live after our own; but the great man is he who in the midst of the crowd
    keeps with perfect sweetness the independence of solitude."
    Ralph Waldo Emerson, Self-reliance 1841
    http://pinpoint.wordpress.com/
     
    Sourcerer, Jan 24, 2007
    #3
  4. Sandy

    Tim Slattery Guest

    "Sandy" <> wrote:

    >HI All,
    >I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof
    >service pack 2 and it works properly on my machine, but when I run the
    >same exe on a different machine (Windows XP Prof SP-2), The application


    You're in the wrong group. You're far more likely to find help in
    microsoft.public.vc.mfc

    --
    Tim Slattery

    http://members.cox.net/slatteryt
     
    Tim Slattery, Jan 24, 2007
    #4
  5. >
    > Is there any chance the sprintf or CString Format function is creating
    > this problem.
    >


    Every chance. It's clear from your code that you don't understand how
    the various types of string available to you work. Also you appear to
    misunderstand sizeof (it doesn't test the length of a string).

    > I have spent lot of time it undertsanding this bug with no success. Any
    > help would be greatly appreciated.


    Rewrite from scratch, write a little at a time, and test thouroughly as
    you go. Ask specific questions in this group. A huge mess of code (and
    it is a mess) and an unfocussed question is unlikely to get you much
    help here.

    I'd also suggest that you learn one string system (i.e. std::string or
    CString or char arrays) and stick with it. std::string is obviously the
    best in general terms.

    John

    >
    > Regards,
    > Sandy
    >
     
    John Harrison, Jan 24, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Belson
    Replies:
    3
    Views:
    645
    Thomas Fritsch
    Apr 19, 2005
  2. Replies:
    2
    Views:
    569
    Roedy Green
    Mar 31, 2006
  3. Scott McPhillips
    Replies:
    0
    Views:
    380
    Scott McPhillips
    Jul 5, 2003
  4. ringos75
    Replies:
    0
    Views:
    966
    ringos75
    Apr 14, 2005
  5. yopwojtek

    Derive from MFC DLL to MFC APP

    yopwojtek, Aug 6, 2005, in forum: C++
    Replies:
    1
    Views:
    388
    Alf P. Steinbach
    Aug 6, 2005
Loading...

Share This Page