V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
rateltalk
V2EX  ›  C++

MFC 长时间运行出现 Buffer too small 错误

  •  
  •   rateltalk ·
    shangdev · Jun 16, 2022 · 2301 views
    This topic created in 1419 days ago, the information mentioned may be changed or developed.

    网上查了一下,大概是以下代码引起的:

    DWORD g_index;
    void main ()
    {
      CString B;
      B.Format(L"%d", g_index + 1); // 时间长会报错:Buffer too small
      g_index++;
    }
    

    上述代码是在 MFC List 表格组件中用来生成自增 ID ,1 、2 、3...的
    App 长时间运行就会出现 Buffer too small ,结合网上查询猜测可能是上述代码引起的。

    所以请教一下如何解决呢?

    3 replies    2022-06-16 11:17:05 +08:00
    dearmymy
        1
    dearmymy  
       Jun 16, 2022
    竟然是 没饭吃,猜测是 CString b 是不是放的位置不对,比如放到 for 循环内部?你试试把 b 变量也全局变量下
    rateltalk
        2
    rateltalk  
    OP
       Jun 16, 2022
    @dearmymy

    我是放到 afx_msg LRESULT CChatRecords::OnShowmessage(WPARAM wParam, LPARAM lParam) {} 里的
    minami
        3
    minami  
       Jun 16, 2022
    %d->%u
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2519 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 15:35 · PVG 23:35 · LAX 08:35 · JFK 11:35
    ♥ Do have faith in what you're doing.