rateltalk
V2EX  ›  问与答

Visual Studio MFC 获取值内存溢出及 Radio 控件函数未定义

  •  
  •   rateltalk · Apr 2, 2022 · 1569 views
    This topic created in 1503 days ago, the information mentioned may be changed or developed.
    新手请教一下出现以下问题是什么原因,以及如何解决

    1 、GetDlgItemText 获取控件 IDC_EDIT_WXID 的输入值时,提示写入到"变量"时缓存区溢出




    2 、GetCheckedRadioButton 获取 Radio 组选中状态时,提示未定义标识符
    3 replies    2022-04-02 23:05:49 +08:00
    ysc3839
        1
    ysc3839  
       Apr 2, 2022
    建议养成看文档的习惯,不要想当然觉得某个参数是什么含义。
    GetDlgItemTextW 最后一个参数是 The maximum length, in characters ,是字符数而不是字节数。用 sizeof 取到的是字节数。https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdlgitemtextw
    这里建议使用 std::size(),或者 ARRAYSIZE, countof 之类的宏。后面这两个不在 C++ 标准中,是某些头文件附带的,不是任何环境都可用。
    GeruzoniAnsasu
        2
    GeruzoniAnsasu  
       Apr 2, 2022
    能上 v 站但不会 googel ?

    GetCheckedRadioButton 是 CWnd 的成员,要不你先找本 c++入门看看……
    rateltalk
        3
    rateltalk  
    OP
       Apr 2, 2022 via iPhone
    @GeruzoniAnsasu #2 可以用 CheckRadioButton ,但是不能用内容里的 GetCheckedRadioButton
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1206 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 17:42 · PVG 01:42 · LAX 10:42 · JFK 13:42
    ♥ Do have faith in what you're doing.