求助,memmove拷贝内存出现错误异常

nacongju6517 2018-04-08 05:12:36
void CInterceptionDriveCommunicationsMFCDlg::OnBnClickedButton1()
{
ULONG uBaseAddress;

uBaseAddress = GetDlgItemInt(IDC_EDIT1);

SetDlgItemText(IDC_EDIT2, (LPCTSTR)uBaseAddress);
}


void CInterceptionDriveCommunicationsMFCDlg::OnBnClickedButton2()
{
ULONG uBaseAddress;
WCHAR szBuffer[0xff] = L"asdsadasdsadasd";

uBaseAddress = GetDlgItemInt(IDC_EDIT2);

memmove((PVOID)uBaseAddress, szBuffer, 0xff);
}


...全文
583 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2018-04-08
  • 打赏
  • 举报
回复
memmove 应该指向的是一个可控的内存区域 猜测 可以定义一个类中的缓冲区变量, 围绕缓冲区操作
class CInterceptionDriveCommunicationsMFCDlg : xxxxx
{
public:
  struct _tagMyBuffer_t
  {
    BYTE bBuffer[1024]; 
    _tagMyBuffer_t()
    {
      memset(this, 0, sizeof(*this));
    }     
  }m_MyBuffer;
};

void CInterceptionDriveCommunicationsMFCDlg::OnBnClickedButton2()
{
  WCHAR szBuffer[0xff] = L"asdsadasdsadasd";

  ULONG uBaseAddress = GetDlgItemInt(IDC_EDIT2);
  if(uBaseAddress >=0 && uBaseAddress + 0xFF  <= sizeof(m_MyBuffer.bBuffer))
  {
    memmove(m_MyBuffer.bBuffer + uBaseAddress,  //基址+偏移
      szBuffer, 0xff);
  }
}
nacongju6517 2018-04-08
  • 打赏
  • 举报
回复
= =对MFC不太了解,具体该怎么做呢?
schlafenhamster 2018-04-08
  • 打赏
  • 举报
回复
uBaseAddress 没有 分配 内存!
nacongju6517 2018-04-08
  • 打赏
  • 举报
回复

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧