rateltalk
V2EX  ›  C++

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

  •  
  •   rateltalk ·
    shangdev · Jun 16, 2022 · 2761 views
    This topic created in 1601 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
    dearmymy
    Jun 16, 2022
    1
    竟然是 没饭吃,猜测是 CString b 是不是放的位置不对,比如放到 for 循环内部?你试试把 b 变量也全局变量下
    rateltalk
    rateltalk
    OP
    Jun 16, 2022
    2
    @dearmymy

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